0

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.

David
  • 1,155
  • 1
  • 13
  • 35
  • 1
    That is not the case. The packages are installed in 'R' environment not RStudio. You should specify the location of library on your machine using ```.libPaths()```. That should help. – makeshift-programmer Oct 11 '19 at 19:08

2 Answers2

2

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)
J.P. Le Cavalier
  • 1,315
  • 7
  • 16
  • Yes, I have included that line. It works for Rstudio, but not in a general script written out of Rstudio in some specific directory. – David Oct 11 '19 at 19:12
  • 1
    Try `library(tidyverse, lib.loc="path/to/your/library")` to specify where the library has been installed – J.P. Le Cavalier Oct 11 '19 at 19:15
  • Thanks, but how do I know where the installation from Rstudio is made? With Rstudio opened, I just typed `install.packages("tidyverse")`. – David Oct 11 '19 at 19:19
  • 1
    As suggested by @makeshift-programmer, you can type `.libPaths()` in RStudio to see where the package have been installed by default. – J.P. Le Cavalier Oct 11 '19 at 19:21
  • 1
    You might have R version conflict. Rstudio might be using a specific version and Rscript might be using other. Try using entire path for Rscript. https://stackoverflow.com/a/26910560/7590064 – Not_Dave Oct 11 '19 at 19:47
2

The solution is you simply use require() to load your package without worrying about the path.

require(dplyr)
Apex
  • 1,055
  • 4
  • 22