Run R Script - Ubuntu Server - r

I've recently compiled R on Ubuntu Server 16.04. I'm attempting to run an R Script using the Rscript function, but I'm running into errors.
When I run the script using Rscript, the output shows the functions as() and new() from the methods package included in the R distribution cannot be found. When I run R interactively, I'm able to use these functions without any problem.
Any help would be tremendously appreciated!

It is a design bug in Rscript: it does not load methods on startup.
Two fixes:
Add library(methods) to your script, or
Do sudo apt-get install r-cran-littler and use r instead of Rscript.
r has been loading methods since day one as this behaviour of Rscript never really made sense.

Related

R Tensorflow installation with no user input in console

I have a basic script in R 4.1 and R Studio which installs TensorFlow 2.
When I run the library installation for Tensorflow, everything works fine with no issues. My issue is that when I call the library and run the install_tensorflow command, the console is asking me to answer a "yes/no" question.
Would you like to install Miniconda? [Y/n]:
My question: How do I answer this with a Y without having to type directly into the console? I want to just run an R Script to install and provision my conda environment without manual intervention. Programmatic User Input.
Here is my full R code:
install.packages("tensorflow")
library(tensorflow)
install_tensorflow(method="auto", conda="auto", version="2.0.0", envname ="tf_test")

Installing a package in R inside a script

I'm a beginner with R. I want to launch R scripts at specific moments, managing this with Linux's cron and launching the scripts as Rscript name_of_the_script.
I have installed tidyverse in Rstudio, with install.packages("tidyverse"). Ok, but I guess that installation is specific to the Rstudio environment. When working in a script (not using Rstudio), and launching that script with Rscript, the library tidyverse is not installed. Even worse, I couldn't install it in the script with install.packages("tidyverse").
What do you suggest? Thanks.
The library is, in fact, probably installed. It is difficult to be sure of what is the problem without more details, but I would guess that you did not load your library in your script. Try to add the following at the beginning on the first line of your script
library(tidyverse)
The solution is you simply use require() to load your package without worrying about the path.
require(dplyr)

How do you run an R script from Windows command line with only RStudio installed?

I have a machine that only has RStudio installed. It does NOT have Rscript.exe which is how I normally run R code from the Windows command line.
How do I run R code from the command line on a Windows machine that only has RStudio installed? They can NOT install the normal R runtime so I need something that comes with RStudio.
Thanks!
Rscript is a scripting front-end, which calls for and uses R. You cannot make successful calls to R without having R. If you just have Rstudio you will not be able to run R since it is assumed that you install R.
Use the portable version of R if you do not have admin privileges.

Running r function with rscript fails after loading package "methods" [duplicate]

I've recently compiled R on Ubuntu Server 16.04. I'm attempting to run an R Script using the Rscript function, but I'm running into errors.
When I run the script using Rscript, the output shows the functions as() and new() from the methods package included in the R distribution cannot be found. When I run R interactively, I'm able to use these functions without any problem.
Any help would be tremendously appreciated!
It is a design bug in Rscript: it does not load methods on startup.
Two fixes:
Add library(methods) to your script, or
Do sudo apt-get install r-cran-littler and use r instead of Rscript.
r has been loading methods since day one as this behaviour of Rscript never really made sense.

Cannot load forecast or RcppArmadillo packages from Script

When I run the commands library(forecast) and library(RcppArmadillo), there is no error. However, when I try to run these commands from a script, my script is unable to execute.
There are a few nuances to this case. Firstly, I only encounter this error on machines with R version > 2.14. I successfully ran this script on R 2.13.0, and encountered the error on machines with R version 2.14.1 and 2.14.2.
Additionally, the command find.package("forecast"), and similarly find.package("RcppArmadillo") does not return an error from inside the script, meaning that the script can locate the packages but cannot load them.
I have successfully ran a script replacing library(forecast) with the following 6 other packages: Rcpp, tseries,fracdiff,qcc,quadprog, zoo, and parallel.
Does anyone know why I cannot load these two packages from a script even though I can load them in the R console, and why this error occurs only for R versions > 2.14? My initial thought was that it might be related to the fact that these packages depend on R>=2.14.
Thank You Very Much.
We found that the issue was that RcppArmadillo depends on the Rlapack.dll file, which the script was not able to locate when loading the library. The solution was to copy the Rlapack.dll file to the library/RcppArmadillo/libs/i386 subfolder. After making this change, we were able to successfully execute our script.
We have two questions about this issue.
1) Why, when executing via R console, were we able to locate the Rlapack.dll file, when, during script execution, we were unable to find the dependent file?
2) Why did this issue occur only in R > 2.14? Was this a result of an update to either the RcppArmadillo or forecast packages?

Resources