Yishi Lin

  • Home

  • Archives

  • Dataset

  • Blog

  • Categories

  • Search

通过Anaconda安装R

Posted on 2019-04-09 In 瞎折腾

在一台不通外网只能连上某个特定mirror的机器上,需要用Python和R。曲线救国,用Conda装好了R,记录一下。

安装Miniconda

安装:

1
2
3
4
5
cd /my_dir
wget http://mirror/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh -b -f -p miniconda3
export PATH=$PATH:/my_dir/miniconda3/bin

替换Anaconda源,并且禁用defaults(因为连不上):

1
2
3
4
5
6
conda config --add channels http://mirror/anaconda/pkgs/free/
conda config --add channels http://mirror/anaconda/cloud/conda-forge/
conda config --add channels http://mirror/anaconda/pkgs/r/
conda config --set show_channel_urls true
conda config --remove channels defaults
conda config --show

创建环境并安装R

创建环境,装r-base,然后就可以用R了!截止到这一步,miniconda一共是833M。

1
2
3
4
conda create -n my-r-env
source activate my-r-env
conda install -c http://mirror/anaconda/pkgs/r/ r-base
R

在Bash里装包

从Aanaconda装R包(其实从CRAN直接装就行了,更符合平时的使用习惯)。

1
2
conda install -c http://mirror/anaconda/pkgs/r/ r-ggplot2
conda install -c http://mirror/anaconda/pkgs/r/ r-data.table

在R里升级/装包

可以看一下包都装在哪里。

1
2
.Library  # 可以看一下包都装在哪里
.libPaths() # 可以看一下包都装在哪里

安装包:

1
2
3
4
options(download.file.method = "wget")  # 不写不行,原因未知,放弃探索
repo = 'http://mirror/CRAN/'
update.packages(repos=repo, ask=F) # 升级所有包
install.packages('devtools', repos=repo) # 安装包

从源码安装自己下载的包:

1
install.packages('xxxxxxxxx.tar.gz', repos=NULL, type="source")

踩坑

  1. 从conda-forge装的r-base无法运行,报错/my_dir/miniconda3/envs/my-r-env/lib/R/bin/exec/R: error while loading shared libraries: libbz2.so.1.0: cannot open shared object file: No such file or directory。但是从pkgs/r/装的就没毛病,放弃。
  2. 安装R包的时候,如果是Github上直接下载的zip,需要在服务器上unzip后重新tar -czf xxx.tar.gz xxxx。否则会报错Error in rawToChar(block[seq_len(ns)])......。
# R # anaconda
迁移到 Zotero + ZotFile + OneDrive
因果推断学习笔记(三):因果推断比赛 ACIC Data Challenge 学习笔记
  • Table of Contents
  • Overview
Yishi Lin

Yishi Lin

24 posts
11 categories
25 tags
RSS
GitHub E-Mail
  1. 1. 安装Miniconda
  2. 2. 创建环境并安装R
    1. 2.1. 在Bash里装包
    2. 2.2. 在R里升级/装包
    3. 2.3. 踩坑
© 2013 – 2021 Yishi Lin
Powered by Hexo v3.9.0
|
Theme – NexT.Gemini v7.3.0