Installing a package in R inside a script

时间秒杀一切 提交于 2020-05-17 06:03:23

问题


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.


回答1:


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)



回答2:


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

require(dplyr)


来源:https://stackoverflow.com/questions/58347125/installing-a-package-in-r-inside-a-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!