在脚本中的 R 中安装包 [英] Installing a package in R inside a script

查看:75
本文介绍了在脚本中的 R 中安装包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 R 的初学者.我想在特定时刻启动 R 脚本,使用 Linux 的 cron 管理它,并将脚本作为 Rscript name_of_the_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.

我已经在 Rstudio 中安装了 tidyverse,使用 install.packages("tidyverse").好的,但我想安装特定于 Rstudio 环境.在脚本中工作(不使用 Rstudio)并使用 Rscript 启动该脚本时,未安装库 tidyverse.更糟糕的是,我无法使用 install.packages("tidyverse") 在脚本中安装它.

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").

你有什么建议?谢谢.

推荐答案

解决方案是您只需使用 require() 加载您的包,而无需担心路径.

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

require(dplyr)

这篇关于在脚本中的 R 中安装包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆