Coder Social home page Coder Social logo

r-script's People

Contributors

drmmu avatar joshkatz avatar khamurdik avatar payousefi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

r-script's Issues

Cannot read property 'data' of undefined

This simple code

var R = require("r-script");
var fs = require("fs");

var data = fs.readFileSync('r_code/sample.xlsx')
var out = R("r_code/sample.R")
  .data(data, 20)
  .callSync();
  
console.log(out);

leads to the following error

TypeError: Cannot read property 'data' of undefined
    at Object.<anonymous> (/Users/**/Desktop/**/**/r/index.js:9:3)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Function.Module.runMain (module.js:701:10)
    at startup (bootstrap_node.js:194:16)
    at bootstrap_node.js:618:3

what am i doing wrong?

Rscript works in netbeans but not when using npm start

I got my R scripts to run when using node js + express in the NetBeans IDE. But when I use npm to install and start the application, the call fails. For debugging purposes, I modified the callAsync function to log to the console as follows:

R.prototype.callSync = function(_opts) {
var opts = _opts || {};
this.options.env.input = JSON.stringify([this.d, this.path, opts]);
console.log("about to call R scripts. options: "+JSON.stringify(this.options));
var child = child_process.spawnSync("Rscript", this.args, this.options);
if (child.stderr){console.log(child.stderr); throw child.stderr;}
return(JSON.parse(child.stdout));
};
and when I run using npm start I get the following log:

about to call R scripts. options: {"env":{"DIRNAME":"C:\Users\User\Documents\00pj8\SUTD 2016\UROP\Aviation Data Analytics\AvDatView\node_modules\r-script","ALLUSERSPROFILE":"C:\ProgramData","APPDATA":"C:\Users\User\AppData\Roaming","CommonProgramFiles":"C:\Program Files\Common Files","CommonProgramFiles(x86)":"C:\Program Files (x86)\Common Files","CommonProgramW6432":"C:\Program Files\Common Files","COMPUTERNAME":"DESKTOP-GH8IIG9","ComSpec":"C:\Windows\system32\cmd.exe","HOME":"C:\Users\User","HOMEDRIVE":"C:","HOMEPATH":"\Users\User","INIT_CWD":"C:\Users\User\Documents\00pj8\SUTD 2016\UROP\Aviation Data Analytics\AvDatView","LOCALAPPDATA":"C:\Users\User\AppData\Local","LOGONSERVER":"\\DESKTOP-GH8IIG9","NB_EXEC_EXTEXECUTION_PROCESS_UUID":"c5fb4205-d1aa-4846-bd1a-67e5694e7fad","NODE":"C:\Program Files\nodejs\node.exe","NODE_EXE":"C:\Program Files\nodejs\\node.exe","NPM_CLI_JS":"C:\Program Files\nodejs\\node_modules\npm\bin\npm-cli.js","npm_config_access":"","npm_config_allow_same_version":"","npm_config_also":"","npm_config_always_auth":"","npm_config_argv":"{"remain":[],"cooked":["run-script","start"],"original":["run-script","start"]}","npm_config_audit":"true","npm_config_audit_level":"low","npm_config_auth_type":"legacy","npm_config_bin_links":"true","npm_config_browser":"","npm_config_ca":"","npm_config_cache":"C:\Users\User\AppData\Roaming\npm-cache","npm_config_cache_lock_retries":"10","npm_config_cache_lock_stale":"60000","npm_config_cache_lock_wait":"10000","npm_config_cache_max":"Infinity","npm_config_cache_min":"10","npm_config_cafile":"","npm_config_cert":"","npm_config_cidr":"","npm_config_color":"true","npm_config_commit_hooks":"true","npm_config_depth":"Infinity","npm_config_description":"true","npm_config_dev":"","npm_config_dry_run":"","npm_config_editor":"notepad.exe","npm_config_engine_strict":"","npm_config_fetch_retries":"2","npm_config_fetch_retry_factor":"10","npm_config_fetch_retry_maxtimeout":"60000","npm_config_fetch_retry_mintimeout":"10000","npm_config_force":"","npm_config_git":"git","npm_config_git_tag_version":"true","npm_config_global":"","npm_config_globalconfig":"C:\Users\User\AppData\Roaming\npm\etc\npmrc","npm_config_globalignorefile":"C:\Users\User\AppData\Roaming\npm\etc\npmignore","npm_config_global_style":"","npm_config_group":"","npm_config_ham_it_up":"","npm_config_heading":"npm","npm_config_https_proxy":"","npm_config_if_present":"","npm_config_ignore_prepublish":"","npm_config_ignore_scripts":"","npm_config_init_author_email":"","npm_config_init_author_name":"","npm_config_init_author_url":"","npm_config_init_license":"ISC","npm_config_init_module":"C:\Users\User\.npm-init.js","npm_config_init_version":"1.0.0","npm_config_json":"","npm_config_key":"","npm_config_legacy_bundling":"","npm_config_link":"","npm_config_local_address":"","npm_config_loglevel":"notice","npm_config_logs_max":"10","npm_config_long":"","npm_config_maxsockets":"50","npm_config_message":"%s","npm_config_metrics_registry":"https://registry.npmjs.org/","npm_config_node_gyp":"C:\\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js","npm_config_node_options":"","npm_config_node_version":"8.12.0","npm_config_noproxy":"","npm_config_offline":"","npm_config_onload_script":"","npm_config_only":"","npm_config_optional":"true","npm_config_otp":"","npm_config_package_lock":"true","npm_config_package_lock_only":"","npm_config_parseable":"","npm_config_prefer_offline":"","npm_config_prefer_online":"","npm_config_prefix":"C:\Users\User\AppData\Roaming\npm","npm_config_preid":"","npm_config_production":"","npm_config_progress":"true","npm_config_proxy":"","npm_config_read_only":"","npm_config_rebuild_bundle":"true","npm_config_registry":"https://registry.npmjs.org/","npm_config_rollback":"true","npm_config_save":"true","npm_config_save_bundle":"","npm_config_save_dev":"","npm_config_save_exact":"","npm_config_save_optional":"","npm_config_save_prefix":"^","npm_config_save_prod":"","npm_config_scope":"","npm_config_scripts_prepend_node_path":"warn-only","npm_config_script_shell":"","npm_config_searchexclude":"","npm_config_searchlimit":"20","npm_config_searchopts":"","npm_config_searchstaleness":"900","npm_config_send_metrics":"","npm_config_shell":"C:\\Windows\\system32\\cmd.exe","npm_config_shrinkwrap":"true","npm_config_sign_git_commit":"","npm_config_sign_git_tag":"","npm_config_sso_poll_frequency":"500","npm_config_sso_type":"oauth","npm_config_strict_ssl":"true","npm_config_tag":"latest","npm_config_tag_version_prefix":"v","npm_config_timing":"","npm_config_tmp":"C:\\Users\\User\\AppData\\Local\\Temp","npm_config_umask":"0000","npm_config_unicode":"","npm_config_unsafe_perm":"true","npm_config_update_notifier":"true","npm_config_usage":"","npm_config_user":"","npm_config_userconfig":"C:\\Users\\User\\.npmrc","npm_config_user_agent":"npm/6.4.1 node/v8.12.0 win32 x64","npm_config_version":"","npm_config_versions":"","npm_config_viewer":"browser","npm_execpath":"C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js","npm_lifecycle_event":"start","npm_lifecycle_script":"node ./bin/www","npm_node_execpath":"C:\Program Files\nodejs\node.exe","npm_package_dependencies_app":"^0.1.0","npm_package_dependencies_cookie_parser":"~1.4.3","npm_package_dependencies_debug":"~2.6.9","npm_package_dependencies_express":"~4.16.0","npm_package_dependencies_http_errors":"~1.6.2","npm_package_dependencies_jade":"~1.11.0","npm_package_dependencies_less_middleware":"~2.2.1","npm_package_dependencies_morgan":"~1.9.0","npm_package_dependencies_r_script":"0.0.3","npm_package_name":"avdatview","npm_package_private":"true","npm_package_scripts_start":"node ./bin/www","npm_package_version":"0.0.0","NPM_PREFIX_NPM_CLI_JS":"C:\Users\User\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js","NUMBER_OF_PROCESSORS":"4","OneDrive":"C:\Users\User\OneDrive","OS":"Windows_NT","Path":"C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\User\Documents\00pj8\SUTD 2016\UROP\Aviation Data Analytics\AvDatView\node_modules\.bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\MySQL\MySQL Utilities 1.6\;C:\Program Files\nodejs\;C:\Program Files\SASHome\SASFoundation\9.4\ets\sasexe;C:\Program Files\SASHome\Secure\ccme4;C:\Program Files\R\R-3.5.1\bin\x64\;C:\Users\User\AppData\Local\Microsoft\WindowsApps;C:\Users\User\AppData\Roaming\npm","PATHEXT":".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC","PROCESSOR_ARCHITECTURE":"AMD64","PROCESSOR_IDENTIFIER":"Intel64 Family 6 Model 78 Stepping 3, GenuineIntel","PROCESSOR_LEVEL":"6","PROCESSOR_REVISION":"4e03","ProgramData":"C:\ProgramData","ProgramFiles":"C:\Program Files","ProgramFiles(x86)":"C:\Program Files (x86)","ProgramW6432":"C:\Program Files","PROMPT":"$P$G","PSModulePath":"C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules","PUBLIC":"C:\Users\Public","SESSIONNAME":"Console","SystemDrive":"C:","SystemRoot":"C:\Windows","TEMP":"C:\Users\User\AppData\Local\Temp","TMP":"C:\Users\User\AppData\Local\Temp","USERDOMAIN":"DESKTOP-GH8IIG9","USERDOMAIN_ROAMINGPROFILE":"DESKTOP-GH8IIG9","USERNAME":"GDRSolutionsDesigner","USERPROFILE":"C:\Users\User","windir":"C:\Windows","input":"[{},"./rscripts/testR.R",{}]"},"encoding":"utf8"}
Warning in utils::install.packages(missing, repos = "http://cran.rstudio.com/", :
'lib = "C:/Program Files/R/R-3.5.1/library"' is not writable
Error in utils::install.packages(missing, repos = "http://cran.rstudio.com/", :
unable to install packages
Calls: needs -> needs_ ->
Execution halted

So it appears that the script is installing a package but doesn't have permissions.
After some more debugging, I see that the variable missing is equal to "jsonlite". So the launch.R script is failing at the line "needs(jsonlite)".

I tried going into RStudio and installing the package "jsonlite". That was successful but it didn't change this output.

It is strange that the script works fine from within NetBeans but not in the npm start context. Any ideas, please? This is a nice solution to the problem of linking to R. I hope I can get it to work.
THanks,
P

require( 'r-script' ) showing error in angularjs 2

require( 'r-script' ) showing error in angularjs 2

ERROR in .//r-script/index.js
Module not found: Error: Can't resolve 'child_process' in 'project_path/node_modules/r-script'
@ ./
/r-script/index.js 2:20-44
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://192.168.1.252:4200 ./src/main.ts

¿Cat() Call could be missing on Launch.R? at unexpected string in json at position 4

I've starting using this library for an android speed detection app wich requires to process the data with R.

I am exposing the result data trought an API, so the app can use the result.

Well first I have faced several problems to run my algorithm within Node.js some solutions was:

  1. install all libraries via Rscript inside the server console not vía needs (you must use install.package and specify a repo)

2)Check if Rscript is in the path and check if the lib folder for installing packages has write permissions in order to use Needs

  1. Install the latest Pull Requests, the master branch has some bugs, reviewing and installing the pull-request in this repo helped me a lot

Well finally I've get stucked on an error from node

ERROR:

unexpected string in json at position 4

It was because the return of the launch.R file was [1] "[35.636]" , where 35.363 is the result of my R algorithm.

I've tried with other results such as data frames and the result was the same [1] "[x1][x2]..."

The problem is that the double quotes are not a valid JSON format

then after hours of thinking, I've decided to call cat( ) function in the Launch.R file and all my problems gone

Replacing this line

do.call(toJSON, .e$out)

with:

output <- do.call(toJSON, .e$out)
cat(output)
My question is:

My workaround is correct? or Im missing something ?

Error in R script ex-sync.R

I am running the sync example code but got the following error:

if (child.stderr) throw child.stderr;
^
Error in R script ex-sync.R
'unable to install packages'

How to fix it

Dependencies propblems

It find needs.r in package folder (./node_modules/r-script/node_modules/needs/needs.R), but needs dependence download by npm in parent node_modules folder by default (./node_modules/needs/needs.R). So in launch.R we need to change path to find needs.R to source(file.path(Sys.getenv("DIRNAME"), "../", "needs", "needs.R"))

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

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

R-script call slow ?

Hi,

I call r-script a lot of times (hundreds). in my node script.
Each call of r-script takes 1s whereas nothing is performed in the R script (just gives back a number without any computation).

In my node script, I put a "console.log(new Date());" before AND after calling r-script -> this is how I evaluated duration of r-script call.

Do you know how to make things faster ?

Thank you in advance
Kind regards
XAvier

Silently failing

Do you have any recommendations for debugging?

const R = require("r-script");

let results = R("../R/test.R")
                       .data('')
                       .callSync();

console.log(results);

returns null for any R script, including the most basic:

test.r

1+1

I verified with cat to file on the first line of my R code that R is never running, but there is no output even in the verbose debugger.

Error: No method asJSON S3 class: histogram

I am trying to call simple R file which will call hist function.
But when I call this function, I am getting following error

Error: No method asJSON S3 class: histogram

Execution halted

below is my R code

x <- c(1,2,3,4,5,6,6)

hist(x, col="lightblue")

and here is my index.js file


var express = require('express');
var R = require("r-script");

var app = express(); app.get('/', function (req, res) 
{      
	var out = R("example/sample.R")
  .data("hello world", 20)
  .callSync();
    console.log(out);

}) 
var server = app.listen(8081, function () {      var port = server.address().port   
   console.log(`Example app listening at http://localhost:${port}`)})

Similarly I cannot execute any other R function. example
x <- c(1,2,3,4,5,6,6) print(summary(x));

I am getting error as below

Error: No method asJSON S3 class: table

Execution halted

Special Considerations for Windows Machines

I personally have a Mac and was using the latest distribution of R at the time of writing (Version 3.5.1). When testing my R code and NodeJS code on a Windows machine for another user, I ran into a couple errors. Hopefully, the below is enlightening for others.

  1. Adding R to PATH

I kept getting this error

events.js:183
     throw er; // Unhandled 'error' event
     ^

Error: spawn Rscript ENOENT
   at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
   at onErrorNT (internal/child_process.js:362:16)
   at _combinedTickCallback (internal/process/next_tick.js:139:11)
   at process._tickCallback (internal/process/next_tick.js:181:9)

I believe NodeJS cannot call R through command prompt.
In order to resolve, you need to add R to PATH for Windows machines.

See http://yizhexu.com/2017/02/r-path/ with excerpt below

1. Verify R is installed in the following path: C:\Program Files\R\R-3.3.2\bin\x86
2. Open the start menu and type in “View advanced system settings”, click on “Environment variables”
3. Under “System variables”, select Path and click on edit.
4. Click “New”, and add the folder address for R to there (C:\Program Files\R\R-3.3.2\bin\x86)
5. Open windows power shell and type in Rterm or R.exe to launch R command line tool

After adding R to PATH, you need to completely restart NodeJS.

  1. Security Issues

You may run into issues with R when updating packages/installing packages because of Windows Security. Make sure that you have granted full control of the R files for your user account.

https://winaero.com/blog/how-to-take-ownership-and-get-full-access-to-files-and-folders-in-windows-10/

https://stackoverflow.com/questions/5059692/unable-to-update-r-packages-in-default-library-on-windows-7

I believe the location is something like C:/Program Files/R/R-3.2.1/library, but I've honestly forgotten at this point. I think there was another location on the Windows machine that I had to change the permissions to allow R to download whatever packages were needed.

  1. Synchronous vs Asynchronous Calls

I kept running into this error

These are the inputs: 2018-01-01, 2019-01-01, E, 2, 8
undefined:1
installing packages:njsonlite
^

SyntaxError: Unexpected token i in JSON at position 0
   at JSON.parse (<anonymous>)
   at Socket.<anonymous> (C:\Users\HP\Desktop\project_mss\mss-server\node_modules\r-script\index.js:35:25)
   at emitOne (events.js:116:13)
   at Socket.emit (events.js:211:7)
   at addChunk (_stream_readable.js:263:12)
   at readableAddChunk (_stream_readable.js:250:11)
   at Socket.Readable.push (_stream_readable.js:208:10)
   at Pipe.onread (net.js:601:20)

If you look at the index.js and launch.R code within the r-script package, it is pretty revealing.

From launch.R we have

source(file.path(Sys.getenv("DIRNAME"), "needs.R"))
needs(jsonlite)

It seemed to me that the last output of R is what tries to get converted to JSON format to pass to NodeJS. However, I couldn't understand why installing packages:njsonlite was the last output (as it was from launch.R which I believe just calls the specific R script you need).

I experimented a LOT over 2 or 3 days and ended up changing to synchronous calls previously from asynchronous calls.

Within my code we changed from

         var plotType = "scatter";
         var fpmScatter = R(fpmMortalityPath)
             .data(req.query.startDate,req.query.endDate,req.query.formType,req.query.userLevel,req.query.userId,plotType)
             .call(function(err, a) {
                 if (err) throw err;
                 res.json(a)
             });
         }

to

        var plotType = "scatter";
        var data = R(fpmMortalityPath)
            .data(req.query.startDate,req.query.endDate,req.query.formType,req.query.userLevel,req.query.userId,plotType)
            .callSync();
                console.log(data);
            res.json(data);
        }

After making this change, the code worked. I am still not sure why this was the case. I speculated that there might be differences between calls between Windows and Mac machines? However, I am not too sure of this theory.

Update npm package for r-script

The npm package is not yet updated according to the latest version on the master branch. (don't know much about npm, but) Can it be made to update on every new pull request that is made to the master branch?

Error - subscript out of bounds

How to fix this issue..

{"output":[null,"","\nAttaching package: ‘lubridate’\n\nThe following object is masked from ‘package:base’:\n\n date\n\n\nAttaching package: ‘dplyr’\n\nThe following objects are masked from ‘package:lubridate’:\n\n intersect, setdiff, union\n\nThe following objects are masked from ‘package:stats’:\n\n filter, lag\n\nThe following objects are masked from ‘package:base’:\n\n intersect, setdiff, setequal, union\n\nError in R script my-r-function.R \n ‘subscript out of bounds’"],"stdout":"","stdoutStatus":0}

keep print null in the example

Hi, I cannot recover the results in the example. I have made sure adding R to system path. Is there anything else I can check? Thank you.

callback in async call called to often

It seems the callback
R(RscriptName) .data({foo: bar} ) .call(callbackRscript)
then callbackRscript seems to be called for each line of R output.
I'd expected the callback is called once R is done and then with one parameter with all the lines from R output.

R error while running async example

I am getting the error while running the async example:
C:\temp\nodeapps\rtest\example.js:9 if (err) throw err; ^ summarise_each()is deprecated. Usesummarise_all(), summarise_at()orsummarise_if()instead. To mapfunsover all variables, usesummarise_all()

This seems to be an R error, see here. Apparently, summarise_each() is deprecated.

Changing to summarise_all() gets rid of the error and gives the expected output:

[ { group: '(40,55]', rating: 46.7143, advance: 41.1429 }, { group: '(55,70]', rating: 64.6154, advance: 41.9231 }, { group: '(70,85]', rating: 77.2, advance: 45.5 } ]

Do I need to install and configure R language?

Script is not working here - using the "Fix bindAll"-workaround fixes the exception "no data...", but now I always get a NULL value back instead of the example string. Now I am wondering, if I maybe need to install R language as basement? Or is it already included in this NPM-package ("no installation required")?
Thx!

installing packages:njsonlite SyntaxError: Unexpected token i

Hi there,
I'm loving your module, and I got it working like a charm on others machines.
However I'm having problems using it on a Windows machine.
It's probably a PATH issue, or R library related issue, but I can't get it work.

I'm using r-script inside a node (v4.2.4) application with the latest r-script npm release (0.0.3) and R 3.3.1

This is the relevant excerpt from my routing file:
index.js

console.log(input);
R('test.R')
 .data(input)
 .call(function(err, d) {
     if (err) res.send('error: ' + err);
     console.log(d)
 })

and this is the console output:

demo_r_frate2
undefined:1
installing packages:njsonlite
^

SyntaxError: Unexpected token i
    at Object.parse (native)
    at Socket.<anonymous> ([.....]\app\node_modules\r-script\index.js:34:25)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:146:16)
    at Socket.Readable.push (_stream_readable.js:110:10)
    at Pipe.onread (net.js:523:20)

Any thought on how to solve this? What I am doing wrong?

Cannot read property 'data' of undefined and outdated ex-async.R

I ran npm install r-script in Users//Documents/workspace-neon/mss-server/ and was testing the example R scripts and javascripts. Specifically example.js with ex-sync.R.

My path was /Users//Documents/workspace-neon/mss-server/node_modules/r-script/example/ and I ran:
node ex.js

I kept getting

    at Object.<anonymous> (/Users/linjo/Documents/workspace-neon/mss-server/node_modules/r-script/example/ex.js:6:3)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3

I believe the fix is documented in https://stackoverflow.com/questions/50093298/r-integration-with-node-script-using-r-script

In index.js, the init function should be:

function init(path) {
  var obj = new R(path);
  _.bindAll(obj, "data", "call", "callSync");
  return obj;
}

Also, in ex-async.R you need to change summarize_each to summarize_all.

Fix for -- SyntaxError: Unexpected end of input

Hi -- not sure if this is still being managed, but I ran into this error and have a fix for it that might help others.

I was running a couple different R scripts that took a little longer to complete. I would receive an Unexpected end of input error, and the log of the actual data was a .

I concluded I was receiving the 'unexpected end of input' error because JSON.parse couldn't parse the string buffer being passed in from the data received from R via Node's child_process.spawn -- so I attempted concatenating the chunks of the data and then running the callback on close instead, and that fixed my issue!

It's possible I was receiving this error for another reason (and if anyone has other ideas, that would be useful), but I'll make a pull request referencing this issue in case it's something you think would be required for others.

Error running sample

Getting this error message, any ideas?
Error in modifyList(list(x = NULL, auto_unbox = T), dataIn[[3]], keep.null = T) :
is.list(val) is not TRUE

Error: spawn E2BIG

I'm getting this error message when the json I'm passing is large.
is there any workaround for it?

Exceptions in R code poorly handled

I'm having troubles when the R script fails with an exception. I'm getting a "SyntaxError: Unexpected end of JSON input" when my R code hits an exception.

The problem is that when I hit an R exception, body is an empty string here

callback(null, JSON.parse(body));

This then causes my whole application to crash!

May I humbly suggest changing this line to

    if (body) callback(null, JSON.parse(body));

both examples (sync and async) doesn't run

Hello,

ex-sync.R : the console.log command returns "null".
It isn't the expected result (cf. README.md)

ex-async.R : in console, returns :

events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: spawn Rscript ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
    at onErrorNT (internal/child_process.js:415:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
Emitted 'error' event at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
    at onErrorNT (internal/child_process.js:415:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)

It isn't the expected result (cf. README.md)

What solution do i have ?
Is the project still maintained ?

Thanks in advance.

How to make a persistent R environment?

If I used R-script in a client-server application, would this mean the call to a script would be made with every connection?

Further, is it possible to have a persistent connection with R? i.e. I want user input from front-end fed to Rscript and then R's output fed to the user and back again.

Weird issue getting observations back to NodeJS

Hello!

First of all, a big thanks for this module, it is indeed a nifty little tool for R developers.

I am having a weird issue with the RScript and the passage of the output to NodeJS.

Using:

needs("arules")
data <- read.transactions(input[[1]], sep = ",")

library(arules)

# default settings result in zero rules learned
groceryrules <- apriori(data, parameter = list(support =
                          0.006, confidence = 0.25, minlen = 2))

summary(groceryrules)
inspect(groceryrules[1:5])

I get the result fine in nodeJS as:
[ { '2': '=>', lhs: '{potted plants}', rhs: '{whole milk}', support: 0.0069, confidence: 0.4, lift: 1.5655, count: 68, _row: '[1]' }, { '2': '=>', lhs: '{pasta}', rhs: '{whole milk}', support: 0.0061, confidence: 0.4054, lift: 1.5866, count: 60, _row: '[2]' } ...]

However, changing the last line to:
inspect(sort(groceryrules, by = "lift")[1:5])

I get no output. If I set the interval to 1:2, it prints correctly the two top observations (by Lift).
Why can't I view more than 2 items when using sort?

Thanks!

Uncaught TypeError: child_process.spawnSync is not a function(…)

Hi,

Tried using the r-script callSync module and found below error with child_process saying spawnSync is not a function.

Uncaught TypeError: child_process.spawnSync is not a function(…)

When I checked README of child_process below message do exist.

===========================

Security holding package

This package name is not currently in use, but was formerly occupied
by another package. To avoid malicious use, npm is hanging on to the
package name, but loosely, and we'll probably give it to you if you
want it.

You may adopt this package by contacting [email protected] and
requesting the name.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.