首先,引用下面一段话“For a package pkg, pkg::name returns the value of the exported variable name in namespace pkg, whereas pkg:::name returns the value of the internal variable name.”
问题:“exported ”与“internal ”是什么意思?区别究竟是什么?请大侠指教!
R: 关于“::”与“:::”
栗子
<br />
> stringr::<br />
stringr::fixed stringr::str_count stringr::str_length stringr::str_pad stringr::str_sub<br />
stringr::ignore.case stringr::str_detect stringr::str_locate stringr::str_replace stringr::str_sub<-<br />
stringr::invert_match stringr::str_dup stringr::str_locate_all stringr::str_replace_all stringr::str_trim<br />
stringr::perl stringr::str_extract stringr::str_match stringr::str_split stringr::str_wrap<br />
stringr::str_c stringr::str_extract_all stringr::str_match_all stringr::str_split_fixed stringr::word<br />
> stringr:::<br />
stringr:::.__NAMESPACE__. stringr:::is.perl stringr:::str_extract stringr:::str_replace_all<br />
stringr:::.__S3MethodsTable__. stringr:::match_to_matrix stringr:::str_extract_all stringr:::str_split<br />
stringr:::.packageName stringr:::perl stringr:::str_join stringr:::str_split_fixed<br />
stringr:::case.ignored stringr:::re_call stringr:::str_length stringr:::str_sub<br />
stringr:::check_pattern stringr:::re_mapply stringr:::str_locate stringr:::str_sub<-<br />
stringr:::check_string stringr:::recyclable stringr:::str_locate_all stringr:::str_trim<br />
stringr:::fixed stringr:::str_c stringr:::str_match stringr:::str_wrap<br />
stringr:::ignore.case stringr:::str_count stringr:::str_match_all stringr:::word<br />
stringr:::invert_match stringr:::str_detect stringr:::str_pad<br />
stringr:::is.fixed stringr:::str_dup stringr:::str_replace<br />
</p>
使用 :::
能够查看已经导出的函数和内部函数。
这里的 stringr:::check_pattern
是一个内部函数,这类函数是写包时抽象出来方便编程者自己用的,对用户不可见,不需要写文档;而 ::
显示的那些函数对用户是可见的,也就是已经导出的函数,一般需要撰写完整的文档。
回复 第2楼 的 nan.xiao:哦,难怪note里说“:::”时提到package maintainer呢。例子好具体,谢谢。再问一个:“stringr”是什么,我试了一下,运行出错?
http://cran.r-project.org/web/packages/stringr/
回复 第2楼 的 nan.xiao:It doesn't work for me.[s:15]
回复 第5楼 的 Dexim Corp deleveled proC mixeD:你是指加载包以后也不好用吗?
回复 第4楼 的 nan.xiao:谢谢,可是我还是有一点不会,只写“stringr::”会报错,冒号后面必须有具体函数名,可是你是怎么做到的呢?
按 tab 补全?
回复 第8楼 的 nan.xiao:I see.....
回复 第9楼 的 Dexim Corp deleveled proC mixeD:怎么弄啊?我还是没明白。不好意思问版主了,我太笨了。
先输入
<br />
library(stringr)<br />
stringr::<br />
</p>
然后连按两次键盘上的 Tab 键
回复 第11楼 的 nan.xiao:我只按了一次tab键,所以。。。真是太不好意思了,这么点东西还问来问去,谢谢版主的耐心[s:13]
不不不,是我一开始没说清楚,我错了 。。。
回复 第13楼 的 nan.xiao:说实话刚开始我也被蒙蔽了 [s:11] 我还以为又有一个奇特的新功能我从没意识到呢