我正在尝试以下功能:
srch = function(srchstr){
print(ls(pattern=srchstr))
}
以下作品:
ls(pattern='ddf')
[1] "ddf"
调用该函数会产生以下输出:
srch('ddf')
character(0)
我尝试了以下方法:
ss = srch('ddf')
character(0)
ss
character(0)
print(ss)
character(0)
unlist(ss)
character(0)
sapply(ss, print)
named list()
sapply(ss, cat)
named list()
cat(ss)
'cat(ss)'根本没有输出!
为什么会这样?&怎么能纠正这个?
答案 0 :(得分:2)
尝试查看.GlobalEnv
:
srch = function(srchstr){
print(ls(pattern=srchstr, envir = .GlobalEnv))
}
编辑 joran更快......