2012-04-19 101 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