Tag Info

Hot answers tagged

25

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


20

The R code highlighter There is an undocumented symbol RLink`Private`rcell 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 RLink`Private`rcell will be gone, replaced with the new ...


17

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


16

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


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


13

Mathematica 9 includes an RLink feature.


12

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


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

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`"]; RLink`InstallR[]] ParallelEvaluate[RLink`REvaluate["fn <- function(max){sum(sin(1:max))}"]] and then, ...


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


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


8

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


6

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


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

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

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

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

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


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

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


3

Place your call to ReinstallJava in init.m file found in $UserBaseDirectory/Kernel.


3

You can use an external R, as described in the answer you link to, and you can install packages into this external R installation. The errors you see are not related to this. Here are the problems with the code: REvaluate needs to be used with a single R expression. It's not possible to pass it multiple expressions. Enclose everything in { ... } to ...


3

Ubuntu 12.04 64 bit If you want to install everything into a user directory: you can download the package "lib64g2c0_3.4.6-6ubuntu3_i386.deb" unpack it in a ~/temp folder with: "dpkg -x lib64g2c0_3.4.6-6ubuntu3_i386.deb ~/temp" make a symbolic link of the content (or move the content if you prefer) of ~/temp/usr/lib64 to: ...


2

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


2

On SUSE 13.1 InstallR[] worked after installing the rpm libg2c33 - The GNU Fortran Compiler Runtime Library, which provides libg2c.so.0



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