Ask Your Question

R through Sage giving errors: Error: object 'sage3' not found

asked 2012-05-16 23:29:26 +0200

Dug_the_Math_Guy gravatar image

I am trying to use R through Sage and I have read about how the interface works so I think I am entering in the right code. I have tried this on two different computers and get the same errors. One is an quad core 64 bit Ubuntu 10 guest on VMWare Workstation 7 with host Win 7 the other is a single core 32bit Ubuntu 12 pure Linux install when I access R methods I get errors of the form:

Error: object 'sageX' not found where X is a number between 0 and 3


Error: object 'sage2' not found


r.read_table(header=True, text = "a b 1 2 3 4") Error: object 'sage3' not found

I did find a trac that seems to be related to the error I'm getting: But this is from 4 years ago, this issue must have been taken care of by now right? I'm using Sage 4.8

Let me know if you have any idea how to fix this or if there might be something I did wrong during the installation


edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted

answered 2012-05-17 18:31:44 +0200

Dug_the_Math_Guy gravatar image

No worries, I actually was able to figure it out from a FAQ at There is a syntactical issue with using R through sage which apparently still hasn't been fixed in Sage 4.8 where you need to use single quotes to tell python to pass a string to R but then R expects a double quoted string, so you have to use single quotes around double quotes:

see: so my

r.read_table(header=True, text = "a b 1 2 3 4") should be:

r.read_table(header=True, text = '"a b 1 2 3 4"') and when I use that syntax it works! I get:
[1] a b X1 X2 X3 X4 <0 rows> (or 0-length row.names) just like in pure R

the other example works too: r.read_csv(DATA+'transaction_data.csv',header=True) but here I am using DATA as a python string variable that is the path to my data file attached to the Sage notebook it needs the double quotes inside single quotes as well as the file name. I just did

sage: print DATA

/home/math_guy/.sage/sage_notebook.sagenb/home/admin/1/data/ and just copy and pasted the path and filename into the hybrid syntax:


and it worked perfect

I'm not even annoyed to use strange syntax after thinking it was problems with my Sage install ;-)

edit flag offensive delete link more


I'm confused as to how this is different from the answer above, but anyway glad it works! Upvote for showing the wiki page, I'd never seen that one before.

kcrisman gravatar imagekcrisman ( 2012-05-17 22:26:30 +0200 )edit

answered 2012-05-16 23:46:49 +0200

kcrisman gravatar image

It just so happens that we have a few answers on this question for you. In this case something like

sage: a = r.read_table(header=True,text='"a b cd e f g\n 1 2 3 4 56 6"')
sage: a
  a b cd e  f g
1 1 2  3 4 56 6
sage: type(a)
<class 'sage.interfaces.r.RElement'>

could work. Using R keywords through Sage is tricky, though, it's true - go to that question and upvote the most useful answer!

edit flag offensive delete link more

answered 2012-05-16 23:42:14 +0200

Dug_the_Math_Guy gravatar image

another clue: the problem appear to be with Sage's interface to R since when I run the notebook in the pure R mode and alter the syntax of the latter comment above I don't get an error ( even though it looks like I got 0 rows in my table since I apparently need to inform R where my EOL's are ):

read.table(header=TRUE, text = "a b 1 2 3 4")

[1] a b X1 X2 X3 X4 <0 rows> (or 0-length row.names)

edit flag offensive delete link more

answered 2012-05-16 23:31:49 +0200

Dug_the_Math_Guy gravatar image

I forgot to mention: I am getting these errors through the notebook

edit flag offensive delete link more


Luckily, this is orthogonal to notebook, the same would happen in command line.

kcrisman gravatar imagekcrisman ( 2012-05-16 23:47:09 +0200 )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


Asked: 2012-05-16 23:29:26 +0200

Seen: 1,980 times

Last updated: May 17 '12