2024-03-16 05:00:05

使用RStudio更新R

如何通过RStudio更新R ?


当前回答

我发现对我来说,在Linux下保持最新状态的最佳永久解决方案是安装r补丁项目。这将使你的R安装保持最新,你甚至不需要在安装之间移动你的包(这在RyanStochastic的回答中有描述)。

对于openSUSE,请参见此处的说明。

其他回答

如果您使用的是windows,则可以使用安装程序。 示例用法

将其粘贴到控制台并运行命令:

## How to update R in RStudio using installr package (for Windows)
## paste this into the console and run the commands
## "The updateR() command performs the following: finding the latest R version, downloading it, running the installer, deleting the installation file, copy and updating old packages to the new R installation."
## more info here: https://cran.r-project.org/web/packages/installr/index.html

install.packages("installr")
library(installr)
updateR()

## Watch for small pop up windows. There will be many questions and they don't always pop to the front. 
## Note: It warns that it might work better in Rgui but I did it in Rstudio and it worked just fine. 

不要用Rstudio更新R。Rstudio不是R, Rstudio只是一个IDE。这个答案是对之前不同操作系统的答案的总结。对于所有的操作系统,提前看看你在这里已经安装的包会发生什么是很方便的。

WINDOWS ->>以管理员身份打开CMD/Powershell,输入“R”进入交互模式。如果这不起作用,搜索并运行RGui.exe,而不是在控制台中写R…然后:

lib_path <- gsub( "/", "\\\\" , Sys.getenv("R_LIBS_USER"))
install.packages("installr", lib = lib_path)
install.packages("stringr", lib_path)
library(stringr, lib.loc = lib_path)
library(installr, lib.loc = lib_path)
installr::updateR()

MacOS ->>可以使用updateR包。这个包不在CRAN上,所以你需要在Rgui中运行以下代码:

install.packages("devtools")
devtools::install_github("AndreaCirilloAC/updateR")
updateR(admin_password = "PASSWORD") # Where "PASSWORD" stands for your system password

请注意,计划在不久的将来合并updateR和installR,以便同时适用于Mac和Windows。

Linux ->>目前安装程序在Linux/MacOS上不可用(请参阅当前版本0.20的文档)。随着R的安装,你可以按照这些说明(在Ubuntu中,尽管在其他发行版中想法是相同的:添加源代码,更新和升级,然后安装)。

我建议使用Windows包安装程序来完成这个任务。这个包不仅会更新您的R版本,而且还会复制和更新所有的包。这里有一个关于这个主题的博客。只需在R Studio中运行以下命令,并按照提示执行:

# installing/loading the package:
if(!require(installr)) {
install.packages("installr"); require(installr)} #load / install+load installr

# using the package:
updateR() # this will start the updating process of your R installation.  It will check for newer versions, and if one is available, will guide you through the decisions you'd need to make.

为了完整起见,答案是:您不能从RStudio内部完成该操作。@agstudy是正确的-你需要安装新的R版本,然后重新启动RStudio,它会自动神奇地使用新版本,正如@Brandon指出的那样。

如果有一个update.R()函数,类似于install.packages()函数或update.packages(函数),那就太好了。

为了安装R,

登录http://www.r-project.org, 点击“CRAN”, 然后选择你喜欢的CRAN网站。我喜欢堪萨斯州:http://rweb.quant.ku.edu/cran/。 点击“下载R for XXX”[其中XXX是你的操作系统] 遵循操作系统的安装过程 重启RStudio 喜乐

等等——那我心爱的包裹怎么办??--

好吧,我使用的是Mac,所以我只能提供Mac的准确细节-也许其他人可以提供windows/linux的准确路径;我相信这个过程是一样的。

为了确保你的包能与R的新版本兼容,你需要:

move the packages from the old R installation into the new version; on Mac OSX, this means moving all folders from here: /Library/Frameworks/R.framework/Versions/2.15/Resources/library to here: /Library/Frameworks/R.framework/Versions/3.0/Resources/library [where you'll replace "2.15" and "3.0" with whatever versions you're upgrading from and to. And only copy whatever packages aren't already in the destination directory. i.e. don't overwrite your new 'base' package with your old one - if you did, don't worry, we'll fix it in the next step anyway. If those paths don't work for you, try using installed.packages() to find the proper pathnames.] now you can update your packages by typing update.packages() in your RStudio console, and answering 'y' to all of the prompts. > update.packages(checkBuilt=TRUE) class : Version 7.3-7 installed in /Library/Frameworks/R.framework/Versions/3.0/Resources/library Version 7.3-8 available at http://cran.rstudio.com Update (y/N/c)? y ---etc--- finally, to reassure yourself that you have done everything, type these two commands in the RStudio console to see what you have got: > version > packageStatus()