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

Rscript works in netbeans but not when using npm start #28

Open
pj16 opened this issue Oct 28, 2018 · 1 comment
Open

Rscript works in netbeans but not when using npm start #28

pj16 opened this issue Oct 28, 2018 · 1 comment

Comments

@pj16
Copy link

pj16 commented Oct 28, 2018

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

@pj16 pj16 changed the title Rscript works in netbeans but not when using npm install Rscript works in netbeans but not when using npm start Oct 28, 2018
@pj16
Copy link
Author

pj16 commented Nov 11, 2018

I solved it myself. You execute the netbeans package by changing directory to bin and then executing "node www". However, the default directory in that case is the bin directory. So the source() commands in R scripts are not looking in the same directory as when you run them in NetBeans. I fixed it by passing the proper directory to the R script from the javascript code.

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