2012-04-19 98 views
1

偶然我创建了一个名为ls的变量,我用ls()发现了它。所以存在一个函数ls()和一个名字相同的变量。我不知道它是什么类型的变量,也不知道内容,因为所有的尝试都无法访问变量。同名变量和函数(ls)在R

ls 

返回了ls()函数的主体。

get("ls") 

返回的GET(LS)错误:模式

get("ls", mode="numeric") 

对象 'LS' 无效的第一个参数 '数字' 未找到

get("ls", mode=!"function") 

是不是一个有效的参数。 那么如何访问变量?我也尝试过类(ls)和str(ls),但都是指ls作为函数。

我找不到合适的问题。但我确信我之前已经阅读过这方面的内容。所以我很抱歉,如果这是一个重复的职位。帮助和链接将不胜感激。

编辑:的dput(ls()[grep("^ls$", ls())])输出为:

"ls" 

编辑:的dput(ls())输出为:

c("bplo.anno", "c", "combinations.formula", "combo.form", "df", "df.group.unique", "df.test", "dir.work", "form.compl", "fun.boot.lm.stepAIC.4", "fun.boot.lm.stepAIC.5", "fun.CoerceListOfVectorToMatrix", "fun.data.preparation", "fun.dcor.DataFrame", "fun.expand.complete.interaction", "fun.g.ellipse.orig", "fun.K_fold", "fun.lappend", "fun.lm.subset", "fun.lm_AIC", "fun.lst.powerset", "fun.MaxToMinModel.adjrsq", "fun.MaxToMinModel.rsq", "fun.plot.circle", "fun.results", "fun.rs.dcor", "fun.vectorcoerce", "group", "height", "i", "j", "k", "ls", "ls.boot", "ls1", "lst.boot.result", "oldwd", "regressor.names", "response.name", "result.df", "rs.dcor", "source.filename", "tbl.bt", "tbl.nm") 
+0

什么'STR(LS)'给你? – csgillespie 2012-04-19 08:20:02

+0

str(ls)返回函数(name,pos = -1,envir = as.environment(pos),all.names = FALSE, pattern) – Sebastian 2012-04-19 08:32:10

+0

我不能复制这个,你确定变量'ls'是否存在?你可以试试'.GlobalEnv $ ls',但我认为如果它存在于你的全局环境中,你应该只需要用'ls'来访问它。 – 2012-04-19 08:38:40

回答

3

一种可能性是,你复制功能ls(),即

ls = ls 

这再现你的“问题”所以

get("ls") 

返回一个函数。你得到了同样的错误消息:

R> get("ls", mode="numeric") 
Error in get("ls", mode = "numeric") : 
    object 'ls' of mode 'numeric' was not found 
R> get("ls", mode=!"function") 
Error in !"function" : invalid argument type 

dput给出了相同的结果:

R> dput(ls()[grep("^ls$", ls())]) 
"ls" 
+0

是的,你是对的,我一定是抄了它,我没有意识到这种可能性,这就解释了它。 – Sebastian 2012-04-19 11:21:46