1. 程式人生 > >CentOS下離線安裝R語言Forecast包

CentOS下離線安裝R語言Forecast包

1.下載Forecast包以及其依賴包,執行下面R指令碼;

getPackages <- function(packs){
  packages <- unlist(
    tools::package_dependencies(packs, available.packages(),which=c("Depends", "Imports"), recursive=TRUE)
  )
  packages <- union(packs, packages)
  packages
}

myPackages <- c("forecast","RcppArmadillo")

packages <- getPackages(myPackages)

download.packages(packages, destdir="E:/Rpackages/", type="source")

2.下載完成之後,將Rpackages壓縮為Rpackages.tar.gz,上傳到centos並解壓;

3.下載stringi依賴的資料包icudt61l.zip(不同的stringi可能會有不同的版本,可以從報錯資訊裡面提取下載路徑),下載,下載完成之後,直接將壓縮包上傳到centos中;

4.安裝stringi,在centos中輸入R,進入R命令模式(指定資料集所在本地位置,否則會報錯installation of package ‘stringi’ had non-zero exit status)

install.packages("包所在路徑/stringi_1.4.3.tar.gz",configure.vars="ICUDT_DIR=icudt61l.zip上一級路徑", repos = NULL, type = "source") 

5.安裝forecast,按順序輸入以下指令,等待安裝完成即可。

# 忽略>,依次輸入>後腳本
>library(tools)
>path <- "下載的離線包解壓後路徑"
>write_PACKAGES(path,type="source")
>myPackages <- c("forecast")
>install.packages(myPackages, contriburl=paste("file:",path,sep=''),type="source")

附註:

    安裝過程中,如果出現had non-zero exit status錯誤,重新安裝即可。

    單個包下載路徑:https://cran.r-project.org/src/contrib/Archive/stringi/

    包依賴查詢路徑:https://cran.r-project.org/web/packages/stringi/

    R語言原始碼包:https://cran.r-proj