R 语言之基础用法

本节主要介绍R的一些常用的基础用法。

参考书籍: "Bioinformatics with R Cookbook"

安装

  1. 安装 CRAN 上的包:

     > install.packages("package_name")
    
  2. 安装 Bioconductor 上的包:

     > source("http://bioconductor.org/biocLite.R")
     > biocLite("limma")
    
  3. 选择镜像网站(因为默认的镜像网速可能慢):

     对于安装 CRAN 上的包:
     > chooseCRANmirror()
    
     对于安装 Bioconductor 上的包:
     > chooseBioCmirror()
    

常用操作

  1. 查看当前用户已安装了什么包:

     > library()
    
  2. 查看已安装 R 的版本信息,操作系统,以及已经载入的包的信息:

     > sessionInfo()  # 这个用法还是很方便好用的。
    
  3. 查看以及改变当前 R 的 path:

     > getwd()  # 查看当前的工作目录
     [1] "/home/user"
    
     > setwd("/home/user/Downloads") # 改变当前的工作目录
     [1] "/home/user/Downloads"
    
  4. 退出:

     > q()
    

帮助

在R下一般安装的包很多,每个包的功能也很多,在命令行下熟练掌握 help 的用法是很重要的.

  1. 查看R官网上的基础文档,入门文档:

     > help.start()
    
  2. 查看某一特定 function/method 的用法:

     > help(sum) # Accesses help file for function sum
     or
     > ?sum   # Searches the help files for function sum
    
     > library("limma")
     > help(eBayes)
     即可,非常方便
    
  3. 在所有已安装的包中以关键词进行搜索某一 function/method :

     > help.search("sum")
     > help.search("heatmap")
     or
     > ??sum
     > ??heatmap
    
  4. 查看某一 function/method 的示例:

     > example(heatmap)
     > example(norm)  # 非常的有用
    
  5. 查看某一个包的帮助信息:

     > library(limma)
     > help("limma") # 可以看到对这个包的简单介绍。
     > help(package="limma")  # 则可以看到除介绍外所有的 function/method 列表。
    
  6. 查看某一个包的文档信息(pdf):

     > vignette(package="affy") # 查看该包有那些文档介绍
     Vignettes in package ‘affy’:
    
     affy                    1. Primer (source, pdf)
     builtinMethods          2. Built-in Processing Methods (source, pdf)
     customMethods           3. Custom Processing Methods (source, pdf)
     vim                     4. Import Methods (source, pdf)
    
     从输出结果可以看到该包有四个文档,想查看某一文档:
     > vignette("vim", package="affy")  # 非常的方便
    

posted on 2015-11-02 21:29  OA_maque  阅读(406)  评论(0)    收藏  举报

导航