4

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.

4
  • This behavior would occur if the executable were R, rather than Rscript; is /usr/bin/Rscript actually a distinct executable, or a manually created link to R? Commented Jan 9, 2018 at 11:14
  • @MartinMorgan I have assumed they were the same thing. I don't think I have made any manual configurations after simply installing R, so it's likely that it's a distinct executable. Commented Jan 9, 2018 at 11:20
  • please show the filesystem attributes of the file and how you're calling it on the command line Commented Jan 9, 2018 at 12:33
  • It is run by means of double-clicking the file. Commented Jan 9, 2018 at 12:48

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I had the same issue but the executable file doesn''t run even if I choose the right app. My screen (black screen) close prompt(like 1 sec) and I can't figure it out why. I work on windows.
@MaryNastase I am not a (regular) Windows user myself. It is probably best to ask a separate question.
1

You're not running RScript, you're running R, So ask R to tell you to run a file:

$  R --help

Usage: R [options] [< infile] [> outfile]
   or: R CMD command [arguments]

Options:
  --args                Skip the rest of the command line
  -f FILE, --file=FILE  Take input from 'FILE'
  -e EXPR               Execute 'EXPR' and exit

So try it this way:

R -f helloworld.R

The question is, why is your Rscript executable bugged and pointing to R?

4 Comments

That's not how Rscript works on my system (version 3.5, 3.6 and dev on Linux). Why does Rscript --help show the output from R --help?
Oh, that's it. So the problem behind the problem is: Rscript is just default points to R. The next question becomes: "Why is R installed but Rscript is not installed?"
Which OS and which R version do you use? How did you install R?
macOS Mojave, R version 3.3.2 installed with 'brew install r'. What had happened is my /usr/local/bin/Rscript got root permissions because I was fooling around with it. and after a new install it got bugged, so then Rscript defaults to R. What I did was rm /usr/local/bin/Rscript and then do a fresh install and now it works as you say.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.