楼主: oliyiyi
3355 20

S4 Classes and Methods [推广有奖]

版主

已卖:2994份资源

泰斗

1%

还不是VIP/贵宾

-

TA的文库  其他...

计量文库

威望
7
论坛币
66105 个
通用积分
31671.0967
学术水平
1454 点
热心指数
1573 点
信用等级
1364 点
经验
384134 点
帖子
9629
精华
66
在线时间
5508 小时
注册时间
2007-5-21
最后登录
2025-7-8

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

楼主
oliyiyi 发表于 2019-1-23 20:47:08 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
介绍r中s4方法的slide

本帖隐藏的内容

S4 Classes and Methods.rar (195.32 KB, 需要: 2 个论坛币) 本附件包括:
  • S4 Classes and Methods.pdf


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Methods classes Method ETH SES

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

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

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

沙发
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.

7
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.

8
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.
缺少币币的网友请访问有奖回帖集合
https://bbs.pinggu.org/thread-3990750-1-1.html

9
oliyiyi(未真实交易用户) 发表于 2019-1-23 21:12:48
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.


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

10
albertwishedu(未真实交易用户) 发表于 2019-1-24 01:03:14

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-2 17:32