如何在 RStudio 中打开项目时自动加载包 [英] How to load packages automatically when opening a project in RStudio

查看:71
本文介绍了如何在 RStudio 中打开项目时自动加载包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我重新启动 RStudio 时,它都要求我重新加载之前在工作区中加载的所有包.我似乎无法弄清楚问题是什么,RStudio 在关闭项目时正在保存项目.

Every time I restart RStudio-it requires me to reload all of the packages that were loaded in the workspace previously. I can't seem to figure out what the problem is, RStudio is saving the projects when it closes them.

如何确保 RStudio 在打开项目时重新加载必要的包?

How can I make sure that RStudio reloads the necessary packages when I open the project?

推荐答案

我想您想说您必须重新加载之前在工作区中加载的所有包.这不是错误,这是设计使然.

I presume you want to say that you have to reload all of the packages that were loaded in the workspace previously. That's not an error, that's by design.

如果你想在项目启动时加载一些包,你可以通过在项目目录中创建一个名为 .Rprofile 的文件来实现,并指定你希望 RStudio 在加载时运行的任何代码项目.

If you want to load some packages at startup in a project, you can do so by creating a file called .Rprofile in the project directory, and specify whatever code you want RStudio to run when loading the project.

例如:

cat("Welcome to this project.\n")
require(ggplot2)
require(zoo)

会在控制台打印欢迎信息,并在每次打开项目时加载 ggplot2zoo.

would print a welcome message in the console, and load ggplot2 and zoo every time you open the project.

另见http://www.rstudio.com/ide/docs/using/projects

这篇关于如何在 RStudio 中打开项目时自动加载包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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