Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
442 views
in Technique[技术] by (71.8m points)

r - Data table error could not find function "."

I am trying to run the following piece of code. Whenever I try to run the code I get the following error: Error in eval(expr, envir, enclos) : could not find function "." How can I fix it? Could someone help?

data(mtcars)
library(data.table)
mtcarsDT <- data.table(mtcars)
mtcarsDT[ mpg > 20,
        .(AvgHP = mean(hp),
        "MinWT(kg)" = min(wt * 453.6)), # wt lbs
        by = .(cyl, under5gears = gear < 5)
        ]

Here is the session info

> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] data.table_1.9.2

loaded via a namespace (and not attached):
[1] digest_0.6.8    htmltools_0.2.6 plyr_1.8.1      Rcpp_0.11.3     reshape2_1.4.1  rmarkdown_0.3.3 stringr_0.6.2  
[8] tools_3.1.2 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Apparently the instructions I offered 2.5 years ago are still current for people using out-of-date versions of Mac R. Assuming you have Xcode and the Command Line Tools installed, you need to first either a) restart R (without loading any of the versions of data.table., reshape2, and dplyr), or b) remove any loaded Namespaces that might conflict with the ability to test-load the new packages:

unloadNamespace('data.table')
unloadNamespace('reshape2')
unloadNamespace('plyr')

Then build from source:

install.packages("data.table", type="source", dependencies=TRUE)

The reason that building from source might work when installing a binary package might not is that the former strategy gets you better checking for version dependencies.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...