Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"(list) object cannot be coerced to type 'double'" error #26

Open
kangtaejun opened this issue Oct 20, 2018 · 0 comments
Open

"(list) object cannot be coerced to type 'double'" error #26

kangtaejun opened this issue Oct 20, 2018 · 0 comments

Comments

@kangtaejun
Copy link

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'’

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant