I did all of the installations from scratch in a virtual conda environment. Then I tried to run R script from within javascript in the following way:

let shCMD = 'Rscript --vanilla R/full_analysis.R ';
  shCMD += '--diff_1 ' + diff_str_1 + '--diff_2 ' + diff_str_2;
  shCMD += '--markers ' + filterStr + '--markers-highlighted ' + colorStr;
  shCMD += '--datasets ' + datasetStr;

  console.log('constructed command for full analysis: ');
  shell.exec('source activate rmain', function(env_code, env_stdout, 
env_stderr) {
    console.log('activated rmain environment')
    if (env_code === 0) {
      shell.exec(shCMD, function(code, stdout, stderr) {

As can be seen I am activating the environment by source activate rmain and I am pretty sure that the next shell command that invokes R script runs in that environment because R script needs argparse package and it is installed only in the rmain virtual environment: in rmain argparse package is successfully imported, but outside of it it gives an error for the argparse absence.

So, now the following line in the R script:

sce <- SingleCellExperiment(list(counts=as.matrix(data[,-1])))

gives me the error:

Error in `rownames<-`(`*tmp*`, value = c("0610007P14Rik", "0610009B22Rik",  : 
  invalid rownames length
Calls: SingleCellExperiment ... elementMetadata -> .local -> rownames<- -> rownames<-
Execution halted

However, if I launch Rstudio from within the rmain environment, the line runs successfully... So, I am puzzled now on what is going on.

  • 2
    $\begingroup$ If it works interactively (in Rstudio) but not as a script it could be because R loads certain libraries for you in an interactive session. You could try adding library(methods) to the script and see if you still have the same problem $\endgroup$ – TimStuart Mar 7 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.