I would like a shell script that launches a new terminal, opens the R environment in the terminal and executes commands in the R environment of the new terminal.
I found a similar Q in the below link,
In order : launch new terminal, launch R environment in the new terminal, execute commands in R environment
But the solution discussed in the thread (Rscript) doesn't work for me.
I'm trying to run the below code,
gnome-terminal -- /bin/sh -c 'R;Sys.getenv("PATH")'
But I'm getting an error when I use (Sys.getenv("PATH")) after R command. I guess it is due to /bin/sh.
gnome-terminal -- /bin/sh -c 'R'
When I run the above code, it opens another terminal and invokes R environment successfully.
Can someone advise how to execute multiple R commands in gnome-terminal.
Related
I am running a script that starts as follows:
#!/usr/bin/env Rscript
#./geneiase -t static -i mydata.tab
If I run the script on my data directly in the command line, it starts without errors or warnings.
But the program is very demanding computationally so I need to submit my jobs to a cluster using a job scheduler called Slurm.
When I write the exact same expression (as in the second paragraph) within the batch job file, and then I submit the job using sbatch, it is immediatelly terminated and does not return any error or output that can help me understand the problem.
I think it has to do with having Rscript in $PATH, but even though I added the directory where Rscript is located to $PATH by: PATH=$PATH:path/to/R/build/R-3.4.0/lib64/R/bin, the problem remains.
Is there a way that I can make Rscript be run in a Slurm batch job?
You'll need to keep the environment of your SLURM script as bash
#!/bin/bash
Since you can run your R script from the command line, it likely means the path to R is already included in your $PATH. On the command line, you might already do something like:
Rscript ./path-to-script/script
To run R from within your SLURM script, it's the same as running from the command line:
Rscript ./path-to-script/script
I would like a shell script that launches a new terminal, opens the R environment in the terminal and executes commands in the R environment of the new terminal.
Here's what I did which is not working :
#!/bin/sh
for i in $(seq 25)
do
gnome-terminal -x sh "R; source('source.r'); function($i)"
done
Where, function() is an r function in the file "source.r"
Please help.
N.B. I don't want to launch the program using the command "Rscript"
EDIT 1 : I don't want to use the command Rscript because the execution halts after sometime (don't know why). In an R environment the script works fine though. Here's what I tried with the command Rscript :
#!/bin/sh
for i in $(seq 25)
do
gnome-terminal -e "Rscript script.r $i"
done
EDIT 2 : I found the reason why the script execution halted with the command Rscript. It was a bug in the code. Now I can make things work with what I did in EDIT 1. Would be nice to know if things can be made to work by not using Rscript i.e. launching R in different terminals and executing commands in each terminal from the shell script.
I want to launch Rcmdr as a command from bash (or any unix shell), perhaps as an alias. R accepts the CMD argument and I could also pipe a script in with <. I would like the R console to stay open, and an interactive RCommander session to be started (Rcmdr is a popular GUI for R, for any newbies reading along, and it seems that you start up R, type library(Rcmdr) and then Commander() to start it up).
I am aware of how to add Rcmdr to my profile, and it appears to always start up if I include library(Rcmdr) in my .Rprofile, on my Linux workstation.
If I pipe my input in with < then this script works up to the point where it says that Commander GUI is launched only in interactive sessions:
library(Rcmdr);
Commander();
However if I run R CMD BATCH ./rcommander.r it just starts up and shuts down immediately, probably giving me some warning about interactive sessions that I didn't see, because CMD BATCH puts R into non-interactive mode and is thus useless for the purpose of "injecting" Rcmdr into an interactive R session.
It appears impossible to "source a file on the command line but run interactively" in R. It also appears that there are command line options to ignore the global and the user profile, but not to specify a custom profile like R --profile-custom ./.Rprofile2
Either I would like to specify a profile that means "Right now I want to start up and use RCmdr" and still be able to run R without it sometimes.
Working on an Ubuntu machine here, I was able to use the advice provided by Dirk in this mailing list post:
nathan#nathan-laptop:~/tmp$ cat rcommander.r
#!/bin/bash
r -lRcmdr -e'while(TRUE) Commander();'
nathan#nathan-laptop:~/tmp$ cat rcommander2.r
#!/bin/bash
Rscript --default-packages=Rcmdr -e 'while(TRUE) Commander();'
The first script uses Dirk's littler package, available on CRAN, and the second uses the standard Rscript executable. As noted, you can kill the process with ctrl + c from your terminal.
I am running a software called CNV-Seq in a Bash script but, I do not have permission to run the following command:
R CMD INSTALL cnv/
The error is
* installing to library '/share/apps/r/3.2.2/intel/lib64/R/library'
Error: ERROR: no permission to install to directory '/share/apps/r/3.2.2/intel/lib64/R/library'
How can I solve this problem without gaining permission.
One approach is creating the bash script that executes R script.
So, the R script will contain:
install.packages("package_name")
Save it as xyz.r
and the bash script will contain:
R -f path_to/xyz.r
Save that as abc.
Run the bash script like this:
bash abc
I am running an R script on the command prompt like this:
> "R.exe" CMD BATCH --vanilla --slave "myscript.R"
The code runs fine in RStudio, but when I run it from command prompt, it stops running after a certain line of code. What's interesting is that the last line that works is a line that itself calls command prompt:
system("cmd /K my_exe_file")
That line actually runs successfully, but then the next line doesn't run. There's no error message. Instead, it keeps appearing on command prompt as if the R code is running indefinitely, but in reality nothing is happening.
Is there a problem with calling command prompt when running R from command prompt? Or is there a different issue I'm missing?