R system call returns error - r

I am trying to execute a python script from within R, with the following command:
system("python ~/speedtest-cli/speedtest-cli --simple")
The error I get is:
python: can't open file '/home/speedtest-cli/speedtest-cli': [Errno 2] No such file or directory
The same command works just fine on the terminal. Am I using the command wrong? Any help is appreciated.

Related

How do I restart R in linux using a line of code?

I need to restart an R session running in linux using a line of code. When the R session restarts I need it to load an existing R script and for the new R session to be clear of previously loaded packages, variables etc.
I've managed to make this work from within an R terminal in Windows using the following code:
library(startup)
restart(args = c('source("existing_code.R")'))
However when the same code runs in a Linux environment I get the following error:
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `'/opt/R/3.6.3/lib/R/bin/exec/R' source("
existing_code.R")'

Why R system is not able to execute hdfs commands?

I am trying to merge some .csv files with the
hdfs dfs -getmerge /path/folderfile filename.csv command.
If I run this command from a terminal or from rstudio's internal terminal, it works fine. If I execute the same command using system("hdfs dfs -getmerge /path/folderfile /destinationpath/filename.csv") it returns the following error:
sh: hdfs: command not found
Warning message:
In system("hdfs dfs -getmerge /path/folderfile /destinationpath/filename.csv") :
error in running command
Thanks for suggestions

Executing R script within R 3.3.1 installed on windows

Sorry for a basic question. I'm trying run a R script called cuffdiff_gtf_attributes (please find it at enter link description here in R 3.3.1 installed on the Windows 7. The script is started with the below line:
#!/usr/bin/env Rscript
When I type cuffdiff_gtf_attributes in R, it says Error: object 'cuffdiff_gtf_attributes' not found. Also, I tried Rscript cuffdiff_gtf_attributes that returned me: Error: unexpected symbol in "Rscript cuffdiff_gtf_attributes".
Moreover, I tried source('cuffdiff_gtf_attributes.R')that seems to work and returned the usage of the script as bellow
Error:
usage: cuffdiff_gtf_attributes --input=<inputGTF> [--output=outputGTF] | --help
But, when I add the arguments as source('cuffdiff_gtf_attributes.R') --input=file.gtf, it says that: Error: object 'file.gtf' not found. I also tried this command as source('cuffdiff_gtf_attributes.R') --input file.gtf, it says that Error: unexpected symbol in "source('cuffdiff_gtf_attributes.R') --input file.gtf"
Sorry, I couldn't post a sample GTF file, you can find a short sample of it at enter link description here
Everything is the current path. Could you please help me out to execute the script?
Thanks in advance
This is a script file. You should run using Rscript instead for Rgui.exe. From a command prompt, navigate to the directory where file.gtf is and run:
"%Programfiles%\R\R-3.3.3\bin\Rscript" cuffdiff_gtf_attributes.R --input=file.gtf

Unable to run R script containing gWidgets2 in command prompt

Say I have a basic r script:
require(gWidgets2RGtk2)
w<-gbasicdialog("Stage 1.5")
visible(w)
I save it, and attempt to run it with command prompt using a batch file that looks like this:
#echo
"C:\Program Files\R\R-3.0.2\bin\x64\Rscript.exe" "C:\Users\Me\Desktop\test\test.r"
PAUSE
When I attempt to run this script, I get this error after all the packages are loaded:
Error in UseMethod(".gbasicdialog") :
no applicable method for '.gbasicdialog'applied to an object of class "NULL"
Calls: gbasicdialog -> .gbasicdialog
Execution halted
Can anyone see if I am doing anything wrong?
Change the script to this:
options(guiToolkit="RGtk2")
library(gWidgets2)
w <- gbasicdialog("Stage 1.5")
visible(w)
Also I assume you meant #echo off as the first line in the batch file. The PAUSE statement could be omitted.

Write errors to file

Is there a way to write my R errors to a file? I run R on bash via:
R --vanilla < myprogram > myprogram.out &
When my program encounters an error (not a syntax error...like an illegal replacement or something) it stops but the error line isn't written to the output file and I don't know what the program was and a lot of the time I log out from the server while it runs.
Thanks,
Josh
Use the R CMD BATCH <infile> <outfile> syntax instead.

Resources