You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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'’
The text was updated successfully, but these errors were encountered:
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
salesforecast.R
` # salesforecast.R
The error coming out is
The text was updated successfully, but these errors were encountered: