ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 17 May 2012 15:27:27 -0500Is there more documentation about how to call R in Sage?http://ask.sagemath.org/question/8970/is-there-more-documentation-about-how-to-call-r-in-sage/ In R,there is built-in data,for example,the "cars" data which contains two columns,one is "speed",and the other one is "dist".When in Sage,how can I access the speed and dist data?r.cars("speed") alter an error "Unknown environment "table" ",so,is there any solution?
Sun, 13 May 2012 07:30:18 -0500http://ask.sagemath.org/question/8970/is-there-more-documentation-about-how-to-call-r-in-sage/Comment by kcrisman for <p>In R,there is built-in data,for example,the "cars" data which contains two columns,one is "speed",and the other one is "dist".When in Sage,how can I access the speed and dist data?r.cars("speed") alter an error "Unknown environment "table" ",so,is there any solution?</p>
http://ask.sagemath.org/question/8970/is-there-more-documentation-about-how-to-call-r-in-sage/?comment=19771#post-id-19771See also http://ask.sagemath.org/question/1420/r-through-sage-giving-errors-error-object-sage3Thu, 17 May 2012 15:27:27 -0500http://ask.sagemath.org/question/8970/is-there-more-documentation-about-how-to-call-r-in-sage/?comment=19771#post-id-19771Answer by Mike Hansen for <p>In R,there is built-in data,for example,the "cars" data which contains two columns,one is "speed",and the other one is "dist".When in Sage,how can I access the speed and dist data?r.cars("speed") alter an error "Unknown environment "table" ",so,is there any solution?</p>
http://ask.sagemath.org/question/8970/is-there-more-documentation-about-how-to-call-r-in-sage/?answer=13575#post-id-13575The current way to do this is
r('cars').subset(select='"speed"')
or
r.subset('cars', select='"speed"')
You need to use double quotes for strings when passing them into the interface. Otherwise, speed will be treated as an "identifier" rather than a string. Additionally,
r('cars')['"speed"']
also works.Mon, 14 May 2012 18:48:47 -0500http://ask.sagemath.org/question/8970/is-there-more-documentation-about-how-to-call-r-in-sage/?answer=13575#post-id-13575Answer by kcrisman for <p>In R,there is built-in data,for example,the "cars" data which contains two columns,one is "speed",and the other one is "dist".When in Sage,how can I access the speed and dist data?r.cars("speed") alter an error "Unknown environment "table" ",so,is there any solution?</p>
http://ask.sagemath.org/question/8970/is-there-more-documentation-about-how-to-call-r-in-sage/?answer=13571#post-id-13571This is not an answer, but a place to aggregate information in the hopes of providing a solution in the future. Obviously Shashank's answer is ideal for anyone interested in just using R straight-up, and several questions on the right will help deal with going between the percent cells and regular cells.
According to the [R Help archive](http://tolstoy.newcastle.edu.au/R/help/06/08/32183.html), the types of R commands that give you this are
cars[,"speed"]
cars$speed
cars[["speed"]]
subset(cars, select = speed)
I'm not sure whether our interface supports the first three types of access to a data structure. At any rate I don't know where it would.
But more troubling is that I can't get the last one to work without something silly like
sage: r.new("subset(cars,select=speed)")
See [this new Trac ticket](http://trac.sagemath.org/sage_trac/ticket/12948) for more details; I at least view this as a bug.Mon, 14 May 2012 06:15:39 -0500http://ask.sagemath.org/question/8970/is-there-more-documentation-about-how-to-call-r-in-sage/?answer=13571#post-id-13571Answer by Shashank for <p>In R,there is built-in data,for example,the "cars" data which contains two columns,one is "speed",and the other one is "dist".When in Sage,how can I access the speed and dist data?r.cars("speed") alter an error "Unknown environment "table" ",so,is there any solution?</p>
http://ask.sagemath.org/question/8970/is-there-more-documentation-about-how-to-call-r-in-sage/?answer=13569#post-id-13569the following in sage notebook gives you access to cars data
%r
cars
Sun, 13 May 2012 10:07:47 -0500http://ask.sagemath.org/question/8970/is-there-more-documentation-about-how-to-call-r-in-sage/?answer=13569#post-id-13569Answer by Jason Grout for <p>In R,there is built-in data,for example,the "cars" data which contains two columns,one is "speed",and the other one is "dist".When in Sage,how can I access the speed and dist data?r.cars("speed") alter an error "Unknown environment "table" ",so,is there any solution?</p>
http://ask.sagemath.org/question/8970/is-there-more-documentation-about-how-to-call-r-in-sage/?answer=13582#post-id-13582Here is more documentation for rpy2, which is what is eventually used to interface with R through the `r` variable: http://rpy.sourceforge.net/rpy2/doc-2.2/html/index.htmlThu, 17 May 2012 02:31:19 -0500http://ask.sagemath.org/question/8970/is-there-more-documentation-about-how-to-call-r-in-sage/?answer=13582#post-id-13582Comment by kcrisman for <p>Here is more documentation for rpy2, which is what is eventually used to interface with R through the <code>r</code>variable: <a href="http://rpy.sourceforge.net/rpy2/doc-2.2/html/index.html">http://rpy.sourceforge.net/rpy2/doc-2...</a></p>
http://ask.sagemath.org/question/8970/is-there-more-documentation-about-how-to-call-r-in-sage/?comment=19782#post-id-19782That is incorrect. We have our own custom pexpect interface. See http://hg.sagemath.org/sage-main/file/c239be1054e0/sage/interfaces/r.pyThu, 17 May 2012 03:50:54 -0500http://ask.sagemath.org/question/8970/is-there-more-documentation-about-how-to-call-r-in-sage/?comment=19782#post-id-19782