8

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 
talat
  • 68,970
  • 21
  • 126
  • 157
hi15
  • 2,113
  • 6
  • 28
  • 51
  • Please try from a clean session of R. Also provide the `sessionInfo()`. –  Feb 14 '15 at 07:04
  • I don't see the `data.table` package. –  Feb 14 '15 at 07:10
  • I reinstalled the package and it shows up in the sessionInfo now but still the error is there. – hi15 Feb 14 '15 at 07:19
  • 1
    This problem seems to occur with `data.table_1.9.2`. It doesn't appear with `data.table_1.9.4`. –  Feb 14 '15 at 07:25
  • When I install package using `install.packages` it automatically installs 1.9.2 version. Could you say, how I can specify to install 1.9.4? – hi15 Feb 14 '15 at 07:33
  • Are you on -nix system? You can always download the latest source and compile on your own. – Roman Luštrik Feb 14 '15 at 08:20
  • 2
    @RomanLuštrik, its is "x86_64-apple-darwin10.8.0", i.e. OSX SnowLeopard. According to [this page](http://cran.r-project.org/web/checks/check_results_data.table.html), there is an error during the compilation of version 1.9.4 on this OS. –  Feb 14 '15 at 08:26
  • It was implemented in 1.9.4. The errors there are tests related to `xts` package (and IIRC they happened because `xts` was also updated around the same time) - so they really aren't errors. You can just install 1.9.4 from source. – Arun Feb 14 '15 at 14:03
  • @Arun As already pointed out, there is a compilation error for version 1.9.4 on SnowLeopard. –  Feb 14 '15 at 14:13
  • Maybe I misunderstood. What's the compilation error get? The link you point to doesn't have any *compilation errors* - just some tests fail (for which I've explained the reason). – Arun Feb 14 '15 at 14:20
  • I guess if the OP tries to compile on is SnowLeopard the version 1.9.4, it will fail. And this is the reason why only version 1.9.2 is available on CRAN for SnowLeopard. –  Feb 14 '15 at 14:29
  • 1
    @Pascal, you'll have to tag me, else I don't see your message. In that case, you can always download the source file, and install it from source by specifying the path to the source file. – Arun Feb 14 '15 at 17:15
  • 4
    @Pascal: This succeeds on an SL build of R (with the proper XCode and Command Line Tools): `install.packages("data.table", type="source", dependencies=TRUE)` and after using `unloadNamespace` on pkgs: 'data.table', 'reshape2' and 'plyr' (in that order, I am able to load version 1.9.4 and run that code. – IRTFM Feb 14 '15 at 19:58
  • Thank you @BondedDust. Good news for the OP. –  Feb 15 '15 at 02:50
  • @42- maybe worth posting that as an answer. I had this exact issue on macOS 10.12 with `data.table` version 1.10 after upgrading from R 3.3 to 3.4, your solution solved it. – user5359531 Nov 21 '17 at 15:29

1 Answers1

3

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.

IRTFM
  • 258,963
  • 21
  • 364
  • 487