数据科学与R语言Cook RR语言与统计分析

「r<-更新」MacOS 安装 R4.0

2020-04-26  本文已影响0人  王诗翔

前往 https://mirrors.tuna.tsinghua.edu.cn/CRAN/ 下载新的版本,鼠标点击安装。

安装完以后启动(重启)RStudio:

R version 4.0.0 (2020-04-24) -- "Arbor Day"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.0 (64-bit)

R是自由软件,不带任何担保。
在某些条件下你可以将其自由散布。
用'license()'或'licence()'来看散布的详细条件。

R是个合作计划,有许多人为之做出了贡献.
用'contributors()'来看合作者的详细情况
用'citation()'会告诉你如何在出版物中正确地引用R或R程序包。

用'demo()'来看一些示范程序,用'help()'来阅读在线帮助文件,或
用'help.start()'通过HTML浏览器来看帮助文件。
用'q()'退出R.

Using library: /Users/wsx/R_library
载入需要的程辑包:pacman
Error: package or namespace load failed for ‘pacman’:
 package ‘pacman’ was installed before R 4.0.0: please re-install it
错误: 没有"install.packages"这个函数
错误: package ‘packrat’ was installed before R 4.0.0: please re-install it
Error: no more error handlers available (recursive errors?); invoking 'abort' restart

可能有些包之前跟系统包装到了一起,更新后找不到了,重新安装下即可。

在系统目录下我们可以看到 2 个不同的 R 版本,所以 3.6 可以安心地删除了。

(base) ShixiangWangdeiMac:~ wsx$ ls /Library/Frameworks/R.framework/Versions/3.6/Resources/library/
KernSmooth   boot         compiler     graphics     mgcv         parallel     splines      tcltk
MASS         class        datasets     grid         nlme         remotes      stats        tools
Matrix       cluster      foreign      lattice      nnet         rpart        stats4       translations
base         codetools    grDevices    methods      pacman       spatial      survival     utils
(base) ShixiangWangdeiMac:~ wsx$ ls /Library/Frameworks/R.framework/Versions/4.0/Resources/library
KernSmooth   boot         compiler     graphics     mgcv         rpart        stats4       translations
MASS         class        datasets     grid         nlme         spatial      survival     utils
Matrix       cluster      foreign      lattice      nnet         splines      tcltk
base         codetools    grDevices    methods      parallel     stats        tools

删除:

$ rm -rf /Library/Frameworks/R.framework/Versions/3.6

最后简单使用 pacman 更新最新的包:

> pacman::p_up()

  There are binary versions available but the source versions are later:
                 binary source needs_compilation
broomExtra        3.0.0  4.0.0             FALSE
graphlayouts      0.6.0  0.7.0              TRUE
pkgbuild          1.0.6  1.0.7             FALSE
proxy            0.4-23 0.4-24              TRUE
statsExpressions  0.4.0  0.4.1             FALSE
systemfonts       0.1.1  0.2.0              TRUE
xml2              1.3.1  1.3.2              TRUE

这次 R 是大版本更新,我发现在更新包的过程中有不少提示要重装一下包,所以最好还是删除之前所有的包进行重装 ┭┮﹏┭┮。


最后附上 ~/.Rprofile 配置文件内容:

#--------------------------------------------
# Set custom library and temp directory for R
# NOTE: please only change following 2 paths
#   Any Question, please email to
#       Shixiang Wang <w_shixiang@163.com>
#--------------------------------------------
.CUSTOM_LIB = "/Users/wsx/R_library" # set your custom library location
#.TMP = "C:/Tools/R/Rtmp"             # set a temp dir for R running
# please do not add '/' at the end !!!

if(!dir.exists(.CUSTOM_LIB)){
  dir.create(.CUSTOM_LIB)
}

.libPaths(c(.CUSTOM_LIB, .libPaths()))
message("Using library: ", .libPaths()[1])


# if(dirname(tempdir()) != .TMP){
#   if(!dir.exists(.TMP)) dir.create(.TMP)
#   cat(paste0("TMPDIR = ", .TMP), file="~/.Renviron", sep = "\n")
# }
# message("Using temp directory: ", .TMP)

#---------------------------------------------------
# pacman is optional, you can delete following code
# If you wanna use pacman, please read:
#   <https://www.jianshu.com/p/cb16ded75672>
# Basically,
# #1, you can use 'p_load' to load multiple package into R
#       like p_load(data.table, dplyr)
# #2, you can use 'p_get' just to install package
# #3, you can use 'p_update' to update all packages
#---------------------------------------------------
if(!require(pacman)){
  install.packages("pacman", dependencies = TRUE)
}
library(pacman)
#----------------------------------------------------
# Copy from rvcheck
##' open working directory
##'
##'
##' @title o
##' @param file to be open; open workding directory by default
##' @return NULL
##' @author Guangchuang Yu
##' @export
o <- function(file=".") {
    os <- Sys.info()[1]
    if (os == "Darwin") {
        cmd <- paste("open", file)
        system(cmd)
    } else if (os == "Linux") {
        cmd <- paste("xdg-open", file, "&")
        system(cmd)
    } else if (os == "Windows") {
        ## wd <- sub("/", "\\", getwd())
        ## cmd <- paste("explorer", wd)
        ## suppressWarnings(shell(cmd))
        cmd <- paste("start", file)
        shell(cmd)
    }
}

source(file.path(if (.Platform$OS.type == "windows") file.path(Sys.getenv("HOMEDRIVE"), Sys.getenv("HOMEPATH")) else Sys.getenv("HOME"), ".vscode-R", "init.R"))

# 使用清华镜像源
options(BioC_mirror="https://mirrors.tuna.tsinghua.edu.cn/bioconductor")

自定义包路径我的第一篇文章就有讲过,微信菜单也有记录,此处不再赘述。

上一篇下一篇

猜你喜欢

热点阅读