Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executable .R file not running, path ignored

Tags:

r

rscript

I'm trying to make helloworld.R run. I have given it executable rights and have added #!/usr/bin/Rscript at the top of the file. (I have also attempted #!/usr/bin/en Rscript). It is a relatively simple file:

#!/usr/bin/Rscript

x <- rnorm(100)
df <- data.frame(x = x)
write.csv(df, "sim_data.csv")

However, any attempt to run the file has been met with the following error

ARGUMENT '/home/path/to/file/helloworld.R' __ignored__

R version 3.4.3 (2017-11-30) -- "Kite-Eating Tree"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

(...)

Surprisingly, renaming the file to helloworld.py lets it run just fine (and outputs sim_data.csv with its expected content), but this seems hacky, so I was wondering if there was a better solution.

like image 949
Frank Vel Avatar asked Oct 25 '25 10:10

Frank Vel


1 Answers

The error message indicates that it is the R executable and not the Rscript executable that was run. You can verify this by using a terminal:

R  /home/path/to/file/helloworld.R         # produces above error
Rscript /home/path/to/file/helloworld.R    # should work
/home/path/to/file/helloworld.R            # should work if file is executable

Most likely your window manager or desktop environment has .R files associated with the R executable and therefore starts R when you doulbe click such a file. How to change that depends on the window manager or desktop environment in use.

like image 153
Ralf Stubner Avatar answered Oct 26 '25 23:10

Ralf Stubner