楼主: oliyiyi
511 18

S4 Classes and Methods [推广有奖]

版主

大师

88%

还不是VIP/贵宾

-

TA的文库  其他...

计量文库

威望
6
论坛币
634736 个
通用积分
22403.5284
学术水平
1396 点
热心指数
1509 点
信用等级
1305 点
经验
329459 点
帖子
8947
精华
66
在线时间
4973 小时
注册时间
2007-5-21
最后登录
2019-9-17

初级学术勋章 初级热心勋章 初级信用勋章 中级信用勋章 中级学术勋章 中级热心勋章 高级热心勋章 高级学术勋章 高级信用勋章 特级热心勋章 特级学术勋章 特级信用勋章

oliyiyi 发表于 2019-1-23 20:47:08 |显示全部楼层
介绍r中s4方法的slide

本帖隐藏的内容

S4 Classes and Methods.rar (195.32 KB)


关键词:Methods classes Method ETH SES

已有 1 人评分学术水平 热心指数 信用等级 收起 理由
davil2000 + 1 + 1 + 1 精彩帖子

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

缺少币币的网友请访问有奖回帖集合
http://bbs.pinggu.org/thread-3990750-1-1.html
stata SPSS
oliyiyi 发表于 2019-1-23 21:07:41 |显示全部楼层
  1. library(ALL)
  2. library(GenomicRanges)
复制代码
回复

使用道具 举报

oliyiyi 发表于 2019-1-23 21:08:12 |显示全部楼层
Use the following commands to install these packages in R.

  1. source("http://www.bioconductor.org/biocLite.R")
  2. biocLite(c("ALL" "GenomicRanges"))
复制代码
回复

使用道具 举报

oliyiyi 发表于 2019-1-23 21:08:41 |显示全部楼层
## Overview
The S4 system in R is a system for object oriented programing. Confusingly, R has support for at least 3 different systems for object oriented programming: S3, S4 and S5 (also known as reference classes).

The S4 system is heavily used in Bioconductor, whereas it is very lightly used in “traditional” R and in packages from CRAN. As a user it can be useful to recognize S4 objects and to learn some facts about how to explore, manipulate and use the help system when encountering S4 classes and methods.
回复

使用道具 举报

oliyiyi 发表于 2019-1-23 21:09:11 |显示全部楼层
The S4 system in R is a system for object oriented programing. Confusingly, R has support for at least 3 different systems for object oriented programming: S3, S4 and S5 (also known as reference classes).
回复

使用道具 举报

oliyiyi 发表于 2019-1-23 21:09:56 |显示全部楼层
The S4 system is heavily used in Bioconductor, whereas it is very lightly used in “traditional” R and in packages from CRAN.
回复

使用道具 举报

oliyiyi 发表于 2019-1-23 21:10:43 |显示全部楼层
As a user it can be useful to recognize S4 objects and to learn some facts about how to explore, manipulate and use the help system when encountering S4 classes and methods.
回复

使用道具 举报

oliyiyi 发表于 2019-1-23 21:11:57 |显示全部楼层
[hr]Important note for programmers
If you have experience with object oriented programming in other languages, for example java, you need to understand that in R, S4 objects and methods are completely separate. You can use S4 classes without every using S4 methods and vice versa.
缺少币币的网友请访问有奖回帖集合
http://bbs.pinggu.org/thread-3990750-1-1.html
回复

使用道具 举报

oliyiyi 发表于 2019-1-23 21:12:48 |显示全部楼层
本帖最后由 oliyiyi 于 2019-1-23 21:14 编辑


S3 and S4 classes

Based on years of experience in Bioconductor, it is fair to say that S4 classes have been very successful in this project. S4 classes has allowed us to construct rich and complicated data representations that nevertheless seems simple to the end user. An example, which we will return to, are the data containers ExpressionSet and SummarizedExperiment.

Let us look at a S3 object, the output of the linear model function lm in base R:

  1. df <- data.frame(y = rnorm(10), x = rnorm(10))
  2. lm.object <- lm(y ~ x, data = df)
  3. lm.object
复制代码
  1. ##
  2. ## Call:
  3. ## lm(formula = y ~ x, data = df)
  4. ##
  5. ## Coefficients:
  6. ## (Intercept)            x  
  7. ##      0.3147      -0.7131
复制代码
  1. names(lm.object)
复制代码
  1. ##  [1] "coefficients"  "residuals"     "effects"       "rank"         
  2. ##  [5] "fitted.values" "assign"        "qr"            "df.residual"  
  3. ##  [9] "xlevels"       "call"          "terms"         "model"
复制代码
  1. class(lm.object)
复制代码
  1. ## [1] "lm"
复制代码


In standard R, an S3 object is essentially a list with a class attribute on it. The problem with S3 is that we can assign any class to any list, which is nonsense. Let us try an example

  1. xx <- list(a = letters[1:3], b = rnorm(3))
  2. xx
复制代码
  1. ## $a
  2. ## [1] "a" "b" "c"
  3. ##
  4. ## $b
  5. ## [1]  0.3380950  0.8861906 -1.1216766
复制代码
  1. class(xx) <- "lm"
  2. xx
复制代码
  1. ##
  2. ## Call:
  3. ## NULL
  4. ##
  5. ## No coefficients
复制代码


At least we don’t get an error when we print it.

S4 classes have a formal definition and formal validity checking. To the end user, this gurantees validity of the object.


缺少币币的网友请访问有奖回帖集合
http://bbs.pinggu.org/thread-3990750-1-1.html
回复

使用道具 举报

albertwishedu 发表于 2019-1-24 01:03:14 |显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 我要注册

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2019-9-19 17:06