304

如何通过 RStudio 更新 R?

4

10 回答 10

292

为了完整起见,答案是:您不能在 RStudio 中执行此操作。@agstudy 说得对——您需要安装较新版本的 R,然后重新启动 RStudio,它会自动使用新版本,正如 @Brandon 指出的那样。

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

所以,为了安装 R,

  1. http://www.r-project.org
  2. 点击“CRAN”,
  3. 然后选择您喜欢的 CRAN 站点。我喜欢堪萨斯州:http ://rweb.quant.ku.edu/cran/ 。
  4. 单击“为 XXX 下载 R”[其中 XXX 是您的操作系统]
  5. 遵循适用于您的操作系统的安装过程
  6. 重启 RStudio

--等等-我心爱的包裹呢??--

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

为确保您的软件包与您闪亮的新版本 R 一起使用,您需要:

  1. 将旧 R 安装中的软件包移动到新版本中;在 Mac OSX 上,这意味着从这里移动所有文件夹:

    /Library/Frameworks/R.framework/Versions/2.15/Resources/library
    

    到这里:

    /Library/Frameworks/R.framework/Versions/3.0/Resources/library
    

    [您将在其中将“2.15”和“3.0”替换为您要升级的任何版本。并且只复制目标目录中还没有的任何包。即不要用你的旧包覆盖你的新“基础”包——如果你这样做了,别担心,无论如何我们会在下一步修复它。如果这些路径不适合您,请尝试使用installed.packages() 来查找正确的路径名。]

  2. 现在您可以通过update.packages()在您的 RStudio 控制台中输入并在所有提示中回答“y”来更新您的包。

    > 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---
    
  3. 最后,为了让自己确信你已经完成了一切,在 RStudio 控制台中输入这两个命令,看看你得到了什么:

    > version
    > packageStatus()
    
于 2013-07-12T23:15:36.560 回答
149

您从官方网站安装新版本的R。

当您重新启动 RStudio 时,它应该会自动以新版本启动。

如果您需要手动执行此操作,请在 RStudio 中转到:工具 -> 选项 -> 常规。

查看@micstr 的答案以获得更详细的演练。

于 2012-12-01T05:43:38.497 回答
117

如果您使用的是 windows,则可以使用installr此处的示例用法

于 2013-12-01T15:17:47.930 回答
66

我建议使用 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.
于 2015-03-14T14:36:37.777 回答
45

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

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

要使用 updateR 从 Rstudio 中更新您的 R 版本,您只需运行以下五行代码

install.packages('devtools') #assuming it is not already installed
library(devtools)
install_github('andreacirilloac/updateR')
library(updateR)
updateR(admin_password = 'Admin user password')

在安装过程结束时,一条消息将向您确认快乐的结局:

everything went smoothly
open a Terminal session and run 'R' to assert that latest version was installed
于 2016-07-27T17:07:32.717 回答
16

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

## 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. 
于 2016-10-17T22:38:30.213 回答
8

有一个名为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 版本。

如果您想了解有关如何使用安装程序包的更多信息,请点击此链接。

于 2016-01-21T06:21:18.710 回答
4

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

于 2013-04-18T16:21:52.027 回答
4

不要使用 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 ->> For the moment installr is NOT available for Linux/MacOS (see documentation for current version 0.20). As R is installed, you can follow these instructions (in Ubuntu, although the idea is the same in other distros: add the source, update and upgrade and install.)

于 2017-11-10T19:44:43.683 回答
1

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

对于 openSUSE,请参阅此处的说明

于 2014-10-15T16:54:12.650 回答