R软件包的安装与使用

R: 软件包的安装与使用

查看软件包路径:

1
2
> .libPaths()
[1] "/Library/Frameworks/R.framework/Versions/3.2/Resources/library"

设置软件包路径:

1
export R_LIBS=/path/to/R/library

安装软件包:

1
install.packages()

源码安装:

1
2
$ R CMD INSTALL /path/to/package_file.tar.gz
$ R CMD INSTALL /path/to/PACKAGE_DIR/

查看已经安装的软件包:

1
library()

载入软件包:

1
2
library(mypackage)
require(mypackage)

查看R启动自动载入的软件包:

1
2
> getOption("defaultPackages")
[1] "datasets" "utils" "grDevices" "graphics" "stats" "methods"

查看当前载入的包:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
> search()
[1] ".GlobalEnv" "package:BondLab" "package:quantmod" "package:TTR"
[5] "package:xts" "package:zoo" "tools:rstudio" "package:stats"
[9] "package:graphics" "package:grDevices" "package:utils" "package:datasets"
[13] "package:methods" "SciViews:TempEnv" "Autoloads" "package:base"
> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.2 (El Capitan)
locale:
[1] zh_CN.UTF-8/zh_CN.UTF-8/zh_CN.UTF-8/C/zh_CN.UTF-8/zh_CN.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] BondLab_0.0.1.9000 quantmod_0.4-5 TTR_0.23-0 xts_0.9-7
[5] zoo_1.7-12
loaded via a namespace (and not attached):
[1] Rcpp_0.12.3 magrittr_1.5 BB_2014.10-1 svUnit_0.7-12
[5] lattice_0.20-33 quadprog_1.5-5 optimx_2013.8.7 minqa_1.2.4
[9] stringr_1.0.0 tools_3.2.3 optextras_2013-10.28 grid_3.2.3
[13] nlme_3.1-122 dfoptim_2011.8-1 urca_1.2-9 rgl_0.95.1441
[17] lmtest_0.9-34 numDeriv_2014.2-1 ucminf_1.1-3 setRNG_2013.9-1
[21] termstrc_1.3.7 sandwich_2.3-4 stringi_1.0-1 lubridate_1.5.0
[25] Rcgmin_2013-2.21 Rvmmin_2013-11.12

查看对象的类:

1
2
3
4
> class(MakeMBSDetails)
[1] "nonstandardGenericFunction"
attr(,"package")
[1] "methods"

查看类的函数:

1
showMethods(class = "listOfMethods")

查看函数定义源码:

1
> findMethods("MakeMBSDetails")

gfortran-4.8的安装

1
2
$ curl -O http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2
$ sudo tar fvxz gfortran-4.8.2-darwin13.tar.bz2 -C /
吴羽舒 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!