2024-03-16 05:00:05

使用RStudio更新R

如何通过RStudio更新R ?


您可以从官方网站上安装一个新版本的R。

当您重新启动RStudio时,它将自动以新版本启动。

如果您需要手动执行,在RStudio中,请转到:工具->选项->通用。

查看@micstr的答案,了解更详细的攻略。

在安装R的新版本后,只需重新启动R Studio。要确认您使用的是>版本的新版本,您应该会看到新的详细信息。

为了完整起见,答案是:您不能从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()

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

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

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

我建议使用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.

有一个名为installr的新包可以在Windows平台上的R中更新你的R版本。这个包是在3.2.3版本下构建的

在R Studio中,单击Tools并选择Install Packages…然后输入名称“installr”并单击install。或者,你也可以在控制台中输入install.packages("installr")。

一旦R studio完成了包的安装,在控制台中输入require(installr)来加载它。

要启动R安装的更新过程,输入updateR()。这个函数将检查R的新版本,如果可用,它将指导您做出需要做出的决定。如果您的R安装是最新的,它将返回FALSE。

如果您选择下载并安装新版本。有一个选项可以将你所有的包从当前的R安装中复制/移动到新的R安装中,这非常方便。

更新过程结束后,退出并重新启动R Studio。R Studio将加载更新的R版本。

如果您希望了解更多关于如何使用安装包的信息,请点击此链接。

如果你使用的是Mac电脑,你可以使用新的updateR包从RStudio更新R版本:http://www.andreacirillo.com/2018/02/10/updater-package-update-r-version-with-a-function-on-mac-osx/

总之,您需要执行以下操作:

要在Rstudio中使用updateR更新你的R版本,你只需要运行这五行代码: Install.packages ('devtools') #假设尚未安装 库(devtools) install_github (andreacirilloac /更新) 库(更新) updateR(admin_password = 'Admin用户密码') 在安装过程结束时,一条消息将确认你的幸福结局: 一切都很顺利 打开一个Terminal会话并运行'R'来断言已经安装了最新版本

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

## 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中,尽管在其他发行版中想法是相同的:添加源代码,更新和升级,然后安装)。