I am trying to automate a docker command in R. However, in order to run the command, zscaler must be turned off for it to work.
The R script is as follows:
shell(cmd = "docker some command", shell = "CMD.EXE")
It creates an error because zscaler is on but works when it's off.
I would like to write a command that turns off zscaler before this R script and then another one after to turn it back on. Is such a command possible?
Related
shell_exec("Rscript C:\R\R-3.2.2\bin\code.R ");
This is the call to script.On calling the above script, the error occurs.
I am trying to call my R script from the above path but no output is being shown. While checking the error logs of PHP, it says 'Rscript' is not recognized as an internal or external command, operable program or batch file.' The script is working fine on the Rstudio but not running on the command line.
Add the Rscript path to your environment variables in Windows:
Go to Control Panel\System and Security\System and click Advanced System Settings, then environment variables, click on path in the lower box, edit, add "C:\R\R-3.2.2\bin"
Restart everything. Should be good to go. Then you should be able to do
exec('Rscript PATH/TO/my_code.R')
instead of typing the full path to Rscript. Won't need the path to your my_code.R script if your php file is in the same directory.
You need to set the proper path where your RScript.exe program is located.
exec ("\"C:\\R\\R-3.2.2\\bin\\Rscript.exe\"
C:\\My_work\\R_scripts\\my_code.R my_args";
#my_args only needed if you script take `args`as input to run
other way is you declare header in your r script (my_code.r)
#!/usr/bin/Rscript
and call it from command line
./my_code.r
If you are running it in Git Bash terminal, you could follow a revised version of the idea suggested by #user5249203: in the first line of your file my_code.R, type the following
#!/c/R/R-3.2.2/bin/Rscript.exe
I assumed that your path to Rscript.exe is the one listed above C:\R\R-3.2.2\bin. For anyone having a different path to Rscript.exe in Windows, just modify the path-to-Rscript accordingly. After this modification of your R code, you could run it in the Git Bash terminal using path-to-the-code/mycode.R. I have tested it on my pc.
I faced the same problem while using r the first time in VS Code, just after installing the language package (CRAN).
I restart the application and everything worked perfectly. I think restarting would work for you as well.
I am attempting to automate a R script using Rstudio Server on ec2 machine.
The R script is working without errors. I then navigated to the terminal on RStudio Sever and attempted to run the R script using the command - Rscript "Rfilename" and it works.
At this point I created a shell script and placed the command above for running the R script in there. This shell command is also running fine - sh "shellfilename"
But when I try to schedule this shell command using crontab, it does not produce any result. I am using the following cron entry :
* * * * * /usr/bin/sh ./shellfilename.sh
I am using cron for the first time and need help debug what is going wrong. My intuition is that there is there is difference in the environments used by the command when I run it on terminal and when I use the same in crontab. In case it is relevant information - am doing all of this on a user account created for myself on this machine so would differ from admin account.
Can someone help resolve this issue? Thanks!
The issue arose due to relative paths used in the script for importing files and objects. Changing this to absolute path resolved the described issue.
I have some command line batch code which I can run in my windows command prompt just fine. I'm basically pushing a local file text file to a remote server using WinSCP command line arguments - https://winscp.net/eng/docs/commandline. These are the commands I use, in order:
to open up winscp command line:
winscp
then to open connection to my server through ssh:
open sftp://myUserName:myPassword#theRemoteServer.net
upload file to remote server:
put directoryMyLocalFileIsIn\fileToUpload.csv /locationOnRemoteServer/whatToNameFileOnRemoteServer.csv
then close connection:
close
This all works fine. But, I want to run this all from within RStudio.. My issue -
after I run:
shell.exec("winscp")
I can see the winscp shell is opened up. But when I try and run my next commands like these:
shell.exec("open sftp://myUserName:myPassword#theRemoteServer.net")
It just doesnt run in that winscp shell that opened up.. I've also used all sorts of combinations of R commands like shell, system2 and shell.
Again, I can open up the winscp shell successfully from within R. But I cant figure out how to then run commands in that shell. Anyone know how to do this?
Thank you.
You need to call WinSCP and specify all commands using a single call from R. The best way to do this is to save your WinSCP commands in a single text file, e.g. myscript.txt:
open sftp://myUserName:myPassword#theRemoteServer.net
put directoryMyLocalFileIsIn\fileToUpload.csv /locationOnRemoteServer/whatToNameFileOnRemoteServer
exit
Then, from the command line, you can call WinSCP as follows (see the WinSCP documentation):
winscp.com /script=myscript.txt
(you might need to specify the exact path for WinSCP and myscript.txt)
Finally, to accomplish this from R, use the system2 command as follows:
system2(
"winscp.com",
args = c("/script=myscript.txt"))
Again, you might need to specify the paths to winscp.com and myscript.txt.
Like in the topic, I'd like to run shiny app with parameters. I need to specify the database file's path from which I will grab the data. The problem is that the file changes sometimes thus I have to modify the file.path every time.
This is the command I use when running application from terminal
R -e "shiny::runApp('../Shiny_visualization')"
I tried
R -e "shiny::runApp('../Shiny_visualization')" --args 'db_path' yet I got an error.
I am working on an ubuntu server. I have an R Script which will run for several days. How would I run it in the background - that when I log out it still runs?!
When I try R script.R it says ARGUMENT 'script.R' __ignored__
First off, to run an R script in batch mode, you have several possibilities; I use the following, which works well:
Rscript scriptname.r
This, however, will run the script in the foreground. This isn’t a problem in tmux per se — just run it in a background tab. However, you can of course run it in the background in the usual way — append &:
Rscript scriptname.r &
Again, this needs to be run inside tmux (or similar) to stay alive once you log out.