如何在 RStudio 中打开项目时自动加载包

如何在 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