解決R安裝rredis問題

一、進入R shell後要安裝rredis(rredis: “Redis” Key/Value Database Client  R client interface to the “Redis” key-value database.)

二、命令:install.packages(“rredis”)

可能會出現

install.packages(“rredis”)
將程式包安裝入‘/home/hadoop/R/x86_64-pc-linux-gnu-library/3.4’
(因為‘lib’沒有被指定)

Warning: 無法在貯藏處https://cloud.r-project.org/src/contrib中讀寫索引:
  無法開啟URL’https://cloud.r-project.org/src/contrib/PACKAGES’

再次嘗試

install.packages(“rredis”)
將程式包安裝入‘/home/hadoop/R/x86_64-pc-linux-gnu-library/3.4’
(因為‘lib’沒有被指定)
試開URL’https://cloud.r-project.org/src/contrib/rredis_1.7.0.tar.gz’
Error in download.file(url, destfile, method, mode = “wb”, …) : 
  無法開啟URL’https://cloud.r-project.org/src/contrib/rredis_1.7.0.tar.gz’
此外: Warning message:
In download.file(url, destfile, method, mode = “wb”, …) :
  URL ‘https://cloud.r-project.org/src/contrib/rredis_1.7.0.tar.gz’: status was ‘Timeout was reached’
Warning in download.packages(pkgs, destdir = tmpd, available = available,  :
  下載程式包‘rredis’時出了問題

再次嘗試

install.packages(“rredis”)
將程式包安裝入‘/home/hadoop/R/x86_64-pc-linux-gnu-library/3.4’
(因為‘lib’沒有被指定)
Warning message:
package ‘rredis’ is not available (for R version 3.4.4) 

三、連續多次嘗試後,花費了很多時間,真的開始懷疑是版本不相容的問題了

開始搜尋怎麼手動安裝rredis,無奈,自己太菜,網上沒有任何資料,也不知道怎麼裝,在找找別人的經驗

於是在https://www.haktansuren.com/installing-r-package-fixing-package-xxx-is-not-available-for-r-version-x-y-z-warning/

是篇英文,不難懂

————————————————————————————————————————————————————–

The default version of `install.packages` somehow stopped working for me on latest version of R. In fact this is regardless of the version of R. I remember having same problem with the older versions of R as well.

Here is the screen shot of the warning. if you are having similar problem, keep on reading.

Package is not available

Anyways, long story short, as everyone knows, if you want to install a package on R, you use:

install.packages('package-name')

And it asks you to pick a mirror repository to search the package in. If you are like me, picking the Cloud, you will soon realize, it will give you a misleading warning that the package is not available for your installed version of R. Well, this is not entirely true based on my experience.

I think not all the repositories include same packages (or versions) for some reason, that’s something I need to confirm it with R support team. If you select different mirror from previous step, and you are lucky enough, you might be able to install the package without any further problem/headache.

I usually use the following code to install package from R and it works 99% of the time.

install.packages('package-name',repos='http://cran.us.r-project.org')

There are several mirrors available you can try, simply change the reposfield on the code above. Find the list of the mirrors here.

You still have problem installing the R package? See my other post here.

Feel free to share your experience, or the mirror works for you the best commenting below.

———————————————————————————————————————————————————————

四、按照這篇英文部落格,嘗試了一下,哇,真的還成功了,恩,現在我用這個命令列成功的機率是100%,我和喜歡

I usually use the following code to install package from R and it works 99% of the time.

(我經常用下面的程式碼去安裝R的包,並且99%都成功了)

install.packages('package-name',repos='http://cran.us.r-project.org')

 

恩,再說一遍,成功了

install.packages(‘rredis’,repos=’http://cran.us.r-project.org’)
將程式包安裝入‘/home/hadoop/R/x86_64-pc-linux-gnu-library/3.4’
(因為‘lib’沒有被指定)
試開URL’http://cran.us.r-project.org/src/contrib/rredis_1.7.0.tar.gz’
Content type ‘application/x-gzip’ length 222376 bytes (217 KB)
==================================================
downloaded 217 KB

* installing *source* package ‘rredis’ …
** 成功將‘rredis’程式包解包並MD5和檢查
** libs
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG      -fpic  -g -O2 -fstack-protector –param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -c libsock.c -o libsock.o
g -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o rredis.so libsock.o -L/usr/lib/R/lib -lR
installing to /home/hadoop/R/x86_64-pc-linux-gnu-library/3.4/rredis/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (rredis)

下載的程式包在
    ‘/tmp/RtmpxoX2rx/downloaded_packages’裡