Ask Your Question
0

Is there more documentation about how to call R in Sage?

asked 2012-05-13 14:30:18 +0100

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

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?

edit retag flag offensive close merge delete

Comments

4 Answers

Sort by ยป oldest newest most voted
1

answered 2012-05-15 01:48:47 +0100

Mike Hansen gravatar image

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

edit flag offensive delete link more
1

answered 2012-05-13 17:07:47 +0100

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

the following in sage notebook gives you access to cars data

%r
cars
edit flag offensive delete link more
0

answered 2012-05-14 13:15:39 +0100

kcrisman gravatar image

This 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, 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 for more details; I at least view this as a bug.

edit flag offensive delete link more
-1

answered 2012-05-17 09:31:19 +0100

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

Here is more documentation for rpy2, which is what is eventually used to interface with R through the rvariable: http://rpy.sourceforge.net/rpy2/doc-2...

edit flag offensive delete link more

Comments

That is incorrect. We have our own custom pexpect interface. See http://hg.sagemath.org/sage-main/file/c239be1054e0/sage/interfaces/r.py

kcrisman gravatar imagekcrisman ( 2012-05-17 10:50:54 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-05-13 14:30:18 +0100

Seen: 583 times

Last updated: May 17 '12