I have a file, called a.r, it has a chmod of 755,
sayHello <- function(){
print('hello')
}
sayHello()
How can I run this via command-line?
转载于:https://stackoverflow.com/questions/18306362/run-r-script-from-command-line
I have a file, called a.r, it has a chmod of 755,
sayHello <- function(){
print('hello')
}
sayHello()
How can I run this via command-line?
转载于:https://stackoverflow.com/questions/18306362/run-r-script-from-command-line
If you want the output to print to the terminal it is best to use Rscript
Rscript a.R
Note that when using R CMD BATCH a.R that instead of redirecting output to standard out and displaying on the terminal a new file called a.Rout will be created.
R CMD BATCH a.R
# Check the output
cat a.Rout
If you really want to use the ./a.R way of calling the script you could add an appropriate #! to the top of the script
#!/usr/bin/env Rscript
sayHello <- function(){
print('hello')
}
sayHello()
I will also note that if you're running on a *unix system there is the useful littler package which provides easy command line piping to R.