# Tag Info

24

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 -> ...

19

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 ...

15

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 ...

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 = ...

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"]]

13

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 ...

12

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. ...

10

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

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 ...

8

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) } "] (* ...

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

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, ...

7

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, ...

7

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 ...

7

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 ...

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]~~"}" ...

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) ...

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

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 ...

3

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"]; This works if you are using the R distribution from http://www.r-project.org/, but if I recall correctly some people said it didn't work ...

3

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. ...

2

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 ...

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