I just started with R and am running it from command line (OS: Mageia). So far it worked fine, I can follow the tutorial (https://www.tutorialspoint.com/r) without problems, doing math, plotting, dataframes - everything works.
However if I try to run a script by usingRscript test.R
I'm getting the error message "unexpected Symbol in Rscript test.R" and I do not know why.
test.R is located in the same directory I started R from so I'm assuming R should find it.test.R itself contains:
print(5)
and should therefore not throw any erors. I have also tried it with an empty file, same problem.
My next idea was that there is something wrong with Rscript asRscript --version
gives me the errors message
object 'Rscript' not found
However, the package "utils" that contains Rscript is installed and trying to update it does not work.
Since I'm new to R I don't know whether this is a case of me not using Rscript properly or there having been a problem with installation. I would be very glad for any help. Thank you in advance.CodePudding user response:
I think you are calling these commands from the R session.
Rscript
is a terminal command to run the R. Open the terminal and move to the directory where test.R
locates and try the command again.
If you want to run test.R
from an R session, use source
function.
source("test.R")