# Tag Info

27

The following is a style for an R cell, inspired by this answer. You can add this to your stylesheet (change the styles to your liking): Cell[StyleData["R"], CellMargins->{{66, 10}, {5, 10}}, Evaluatable->True, Background->RGBColor[1,1,0.85], AutoQuoteCharacters->{}, CellEvaluationFunction -> (REvaluate["{"<>ToString@...

23

I wrote a small package for this. The main reason why I'm posting it here is to get some feedback on how to improve it. I'm new both R and RLink. You can get the package here. Please see the installation instructions in README.md, especially if you're a Mac user (important!). How does it work? RLink does not play well with igraph objects, so an edge-...

21

The R code highlighter There is an undocumented symbol RLinkPrivatercell When you type it and press Shift+Enter, you get a syntax-highlighted R code cell based on my real-time syntax highlighter, which is connected to REvaluate and highlights the code as you type. Note that the cell where you type RLinkPrivatercell will be gone, replaced with the new ...

20

Based on @b.gatessucks answer and on @RahulNarain comment tip, I created this functions for the multiplicative decompose case. I changed @b.gatessucks method for seasonality to keep it closer from R method, and used TemporalData to easily handle time interval. decompose[data_,startDate_]:=Module[{dateRange,plot,plotOptions,observedData,observedPlot,...

15

Wolfram website What's New? has quite a few cool examples of new features. We are interested here in Using Higher-Order Functions and Closures to Structure Code: Flexible Plotting Routines I will give it here to apply to your specific code. "This example illustrates some means of code composition supported by RLink, which allow smooth and productive ...

15

Along the lines of Yamareth's answer, but probably an even better technique, is to put the following into $UserBaseDirectory/Kernel/init.m: Needs["JLink"] SetOptions[InstallJava, JVMArguments->"-Xmx32g"] SetOptions[ReinstallJava, JVMArguments->"-Xmx32g"] ReinstallJava[] By setting the default options, you will get the desired heap size any time you ... 14 Mathematica 9 includes an RLink feature. 14 Erich Neuwirth on MathGroup mentioned a solution for Windows (free for non-commercial applications) that you can download here. Here is his example with small updates from Sasha and Mark Fisher. After downloading the R instalation and DCOM server stuff I tried it and it seems to work just fine. Needs["NETLink"] myR = CreateCOMObject["StatConnectorSrv.... 13 The following seems a little more elegant. data = Import["http://www.massey.ac.nz/~pscowper/ts/cbe.dat"]; ts = TemporalData[data[[2 ;; -1, 1]], {"1958", Automatic, "Month"}]; DateListPlot[ts["Path"]] TemporalData can also store multiple paths. ts2= TemporalData[Transpose[data[[2 ;; -1]]], {"1958", Automatic, "Month"}]; DateListPlot[ts2["Paths"]] 11 While you come back with a version 9 solution here is an old school approach : The first entry is labels so I removed it : rawData = Import["http://www.massey.ac.nz/~pscowper/ts/cbe.dat"][[2 ;;]]; Added the dates to the imported data : they are monthly dates starting {1958, 1, 1} : data = Transpose[{NestList[DatePlus[#, {1, "Month"}] &, {1958, 1, 1},... 11 Unfortunately package installation for RLink works currently on Windows only. Also, for Windows, you have an option of using your own version of R. While fixing package installation for other platforms may be harder, I hope we will have the functionality of using own version of R with RLink to work on other platforms reasonably soon. That would of course ... 11 Here is a possibility: Needs["RLink"] InstallR[] and now StringJoin@Riffle[#, "\n"] &@ REvaluate["{ data(iris) reg <- lm( Sepal.Length ~ Species, data=iris ) summary.text <- capture.output(print( summary(reg)) ) }"] 9 To overcome some limitations of RLink with regard to performance and parallelizability, I also created a LibraryLink based interface to igraph: IGraph/M It does does not have full coverage of igraph functions, but it does provide much of the functionality that is not in Mathematica, in particular: Centrality measures for weighted graphs Edge and vertex ... 9 It is actually possible, if you run several copies of RLink in parallel. This would mean several parallel kernels, R and JVM processes. Here is an example (I have 6 cores): ParallelEvaluate[Needs["RLink"]; RLinkInstallR[]] ParallelEvaluate[RLinkREvaluate["fn <- function(max){sum(sin(1:max))}"]] and then, ParallelTable[RLinkRFunction["fn"][i],{i,... 9 Short answer From the documentation - example df=REvaluate[" { age <- 18:23 height <- c(76.1,77,78.1,78.2,78.8,79.7) name <- c(\"John Young\",\"Jane Ty\",\"john Ed\",\"Mary Ann\",\"Thomas Ed\",\"John Wood\") village <- data.frame(age=age,height=height,name=name) as.data.frame(village) } "] (* RDataFrame[... 8 The documentation says, and I quote, Using Your Own R Distribution (Windows only) On Windows, it is currently possible for you to use your own R distribution with RLink, which may have a number of advantages in certain circumstances. For example, you already have a customized R distribution that you would like to continue using for everything, ... 8 The problem The full answer would require venturing into quite sophisticated matters, and also some of them are not yet fully clear to me. What I can tell right now that your use case hits the borderline between what can be fully imported into RLink (in the sense that it can then be equivalently exported back), and what appears to be imported correctly but ... 7 Update: This is now fixed in Mathematica 10.0.1. This is an issue on Windows only. We are aware of this, and it is planned to get this fixed in the next release of Mathematica. If I get the fix earlier and it is easy enough to create a patch, I will post the workaround here. As far as I know, there is no such issue with R 3.x.x on Linux. Currently, RLink ... 7 The following works for me in reasonable time, when I have about 3Gb free of RAM: Needs["RLink"] InstallR[] Create the large list in R: REvaluate["tmplist <- vector('list',1000);"]; REvaluate[ "for (i in 1:1000) tmplist[[i]] <- matrix(rnorm(200*1000),200,1000)" ]; // AbsoluteTiming (* {15.8774, Null} *) Test the memory use on the R side: ... 6 Try like this in a fresh kernel: Needs["RLink"] SetEnvironment["DYLD_LIBRARY_PATH" -> "/Library/Frameworks/R.framework/Resources/lib"]; InstallR["RHomeLocation" -> "/Library/Frameworks/R.framework/Resources"]; Update: With Mathematica 10.0.1 (but not 10.0.0), use InstallR["RHomeLocation" -> "/Library/Frameworks/R.framework/Resources", "... 5 Here is a possible RLink - based solution. I will use Windows version, since it is easiest for me right now to test on Windows, but it should work on other platforms as well with a few obvious modifications. First, here is a sample Mathematica script I used to test: Needs["RLink"] InstallR[] Pause[10] REvaluate["{ testdata <- rnorm(100) ... 5 I have R installed separately and can do : InstallR["RHomeLocation" -> "/usr/lib64/R"] I am able to run the examples provided in the documentation. I use Fedora 17 64 bit. 5 This looks like very useful function for e.g. economic time series. If this can be done easily in R does it need to be done in Mathematica? With the qualifier that this is my first day testing 9 he is my attempt at the alternative: Needs["RLink"] InstallR[]; data = REvaluate["{ url <- \"http://www.massey.ac.nz/~pscowper/ts/cbe.dat\" CBE <... 5 Short Answer R cannot handle expressions that are nested very deeply. You will have to find a way to simplify your expressions. Long Answer I can reproduce the crash on V9 under Windows 7 64-bit with a simpler setup. Start with these definitions: Needs["RLink"] InstallR[]; expr[depth_] := "function(x){"~~Nest["1+("~~#~~")"&, "x", depth]~~"}" ... 4 Place your call to ReinstallJava in init.m file found in$UserBaseDirectory/Kernel.

4

In my experience economists tend not to write time-series decomposition algorithms of the their own but rather use well established ones. Among them two most well known are ARIMA-X13 and TRAMO-SEATS. Both are implemented by the US Census Bureau and executables are available here. I've tried and implemented a simple package that calls the CB's files in the ...

4

I also had this problem on Ubuntu 12.04, but this solution didn't help me. I think I've gotten it solved though. I suspect that several of my steps were unnecessary (or unnecessarily convoluted) but here goes: First, make the R launch script and binary installed by Mathematica executable. I don't know if Mathematica actually runs these, but it did allow ...

4

The "RHomeLocation" option must be set to the base directory of the R installation, not the directory containing the binaries. Please try to set it to C:\Program Files\R. Quoting the docs: You can specify the location by using the "RHomeLocation" option to InstallR, calling it as follows. InstallR["RHomeLocation" -> "LocationOfYourRDistribution"] ...

4

What I suspect is happening is that your flavor of Linux either lacks certain libraries which we considered standard, or has versions of those libraries which are in conflict with some of the ones we ship with the internal R distribution. Unfortunately, it is not easy to diagnose exactly which libraries are problematic, but I will try to follow up on this. ...

4

As the error says, the variable info that you are referring to does not exist in the R workspace. What you need to do is transfer the data from Mathematica to R. One way is to create the variables x1, x2 and y in R using RSet data = {{"x1", "x2", "y"}, {0, 2, 1}, {1, 5, 0}, {3, 3, 2}, {5, 9, 4}, {3, 4, 5}, {7, 10, 7}}; RSet[First[#], Rest[#]] & /@ ...

Only top voted, non community-wiki answers of a minimum length are eligible