"(list) object cannot be coerced to type 'double'" error
kangtaejun opened this issue · comments
캉태준 commented
So, here's the thing, I'm integrating the R on my node project, however, I don't know how to import data properly from nodejs to R-script. I've been trying in forever.
Here's my latest code:
admin.js
var R = require("r-script");
var getSales = function() {
const db = require('../db.js')
let sql = `SELECT total_sales FROM sales_tbl`
db.query(sql, (error, results, fields) => {
if (error) throw error
console.log(results);
var dataframe = results.map(a => a.total_sales);
dataframe = JSON.stringify(dataframe)
dataframe = dataframe.slice(1, -1)
console.log(dataframe);
var out = R("./public/salesforecast.R")
.data(dataframe)
.callSync();
console.log(out);
return out
})
}
salesforecast.R
` # salesforecast.R
x <- (input)
s <- as.numeric(12)
numfore <- as.numeric(12)
x <- ts(x, frequency = s)
fit <- HoltWinters(x, seasonal = 'additive')
p <- predict(fit, numfore, prediction.interval = TRUE) `
The error coming out is
/home/pauljohn/workspace/the-sims-project/node_modules/mysql/lib/protocol/Parser.js:80
throw err; // Rethrow non-MySQL errors
^
Error in R script ./public/salesforecast.R
‘(list) object cannot be coerced to type 'double'’