S******y 发帖数: 1123 | 1 I have downloaded and installed 'ada' package in R.
I am trying to see its source code.. but without success...
> library(ada)
> ?ada
> ada
function (x, ...)
UseMethod("ada")
======================================================
why some package/functions in R show source code but some don't?
Thanks. |
C******t 发帖数: 72 | 2 Go to CRAN website to download the source code. I guess some function is
written in C and precompiled, therefore, you cann't see the sourece code
from R directly.
http://lib.stat.cmu.edu/R/CRAN/ |
S******y 发帖数: 1123 | |
s*****n 发帖数: 2174 | 4 R里面有个很tricky的冒号办法, 一直加冒号直到显示为止, 有时需要3-4个冒号.
我一般是这样的流程:
> methods(ada)
[1] ada.default* ada.formula*
> find("ada")
[1] "package:ada"
> ada::ada.default
Error: 'ada.default' is not an exported object from 'namespace:ada'
> ada:::ada.default
## 这次显示了, 需要三个冒号.
【在 S******y 的大作中提到】 : I have downloaded and installed 'ada' package in R. : I am trying to see its source code.. but without success... : > library(ada) : > ?ada : > ada : function (x, ...) : UseMethod("ada") : : ====================================================== : why some package/functions in R show source code but some don't?
|
S******y 发帖数: 1123 | 5 Thanks songkun!
It works like a charm... 8-) |
s*****n 发帖数: 2174 | 6 hehe, 我看到你问这个问题就在笑, 我之前很长一段时间内, 也有同样的困惑.
后来在我们公司一个R大牛的seminar上学来的.
【在 S******y 的大作中提到】 : Thanks songkun! : It works like a charm... 8-)
|
z**k 发帖数: 378 | 7 这个叫做Genetic function,我记得好象是S Language里就有定义的吧(具体记不清楚
了),
有一点点类似C++里面的virtual function,根据不同的object类型来调用不同的函数。同样
类似的
函数还有predict,print等等,你看一下源代码,那个NAMESPACE文件,应该有个
S3method的
函数吧,读一下S3method的CRAN手册就应该清楚了。
其实道理很简单,就是让predict对不同的object调用不同的函数,当你的input是一个
lm的
object的时候,predict就变成了predict.lm,当你的object是glm的时候,predict就
变成
了predict.glm,以此类推。因为绝大多数统计模型都需要做预测,利用Genetic
Function就不
再需要根据不同的object来命名预测函数。
R里面这样的函数很多,几乎每一个package都会用到,你可以写一个简单的package实
现一下
default print功能就了解了。
【在 S******y 的大作中提到】 : I have downloaded and installed 'ada' package in R. : I am trying to see its source code.. but without success... : > library(ada) : > ?ada : > ada : function (x, ...) : UseMethod("ada") : : ====================================================== : why some package/functions in R show source code but some don't?
|
z**k 发帖数: 378 | 8 你要看Source Code,还是去下载未编译的Package source吧,因为R cmd窗口里的
source
code吧comment都删掉了,反而不利于你阅读。如果你看package source里面的src文件
夹,一定
会看到诸如ada.xxx.R, ada.yyy.R的的文件,那个就是Genetic function的具体定义了。
【在 S******y 的大作中提到】 : I have downloaded and installed 'ada' package in R. : I am trying to see its source code.. but without success... : > library(ada) : > ?ada : > ada : function (x, ...) : UseMethod("ada") : : ====================================================== : why some package/functions in R show source code but some don't?
|
s*r 发帖数: 2757 | 9 貌似到3个:就到顶了
https://svn.r-project.org/R/trunk/doc/manual/R-intro.texi
There are two operators that work with namespaces. The double-colon
operator @code{::} selects definitions from a particular namespace.
In the example above, the transpose function will always be available
as @code{base::t}, because it is defined in the @code{base} package.
Only functions that are exported from the package can be retrieved in
this way.
The triple-colon operator @code{:::} may be seen in a few places in R
code:
【在 s*****n 的大作中提到】 : R里面有个很tricky的冒号办法, 一直加冒号直到显示为止, 有时需要3-4个冒号. : 我一般是这样的流程: : > methods(ada) : [1] ada.default* ada.formula* : > find("ada") : [1] "package:ada" : > ada::ada.default : Error: 'ada.default' is not an exported object from 'namespace:ada' : > ada:::ada.default : ## 这次显示了, 需要三个冒号.
|