Ask Your Question
1

r.xyz isn't working anymore? (R Project)

asked 2017-12-08 11:07:43 -0500

Kristen Barth gravatar image

I am a beginner to Sage but I used to work with R. I know that I can create a R syntax cell by putting %r at the beginning of the cell. But there are a lot of examples which use the r.xyz syntax (for example: x = r([10.4,5.6,3.1,6.4,21.7]); x). But none of these examples work for me, what am I doing wrong?

edit retag flag offensive close merge delete

Comments

We need much more information to understand your problem. Which version of Sage were you using before it failed? Was it Sage on your computer or online? Was it the Sage notebook or Jupyter?

vdelecroix gravatar imagevdelecroix ( 2017-12-08 15:04:39 -0500 )edit

+1 with Vincent. What did you type precisely to get an error ? On latest Sage version, i have:

sage: x = r([10.4,5.6,3.1,6.4,21.7]); 
sage: x
[1] 10.4  5.6  3.1  6.4 21.7
tmonteil gravatar imagetmonteil ( 2017-12-08 16:58:05 -0500 )edit

Thanks for reporting this bug. This bug is now tracked at https://github.com/sagemathinc/cocalc/issues/2564 .

slelievre gravatar imageslelievre ( 2017-12-10 13:08:29 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2017-12-09 12:07:39 -0500

this post is marked as community wiki

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

Hello, the r in CoCalc's Sage Worskheets is different from the r in Sage itself. The reason is that %r at the top of a cell launches the execution in an R jupyter kernel. Different philosophy altogether.

However, you can do r = R() in a sagews which creates and defines the same R-interpreter r.

r = R()
r.summary(r([1,2,3,2]))

https://cocalc.com/share/20e4a191-73e...

edit flag offensive delete link more

Comments

Thank you!

Kristen Barth gravatar imageKristen Barth ( 2017-12-09 14:20:04 -0500 )edit
1

answered 2017-12-09 00:45:44 -0500

slelievre gravatar image

When you start Sage, r is the R interpreter.

Maybe you defined r as something else?

In a new Sage session, the following works:

sage: r
R Interpreter
sage: x = r([10.4,5.6,3.1,6.4,21.7]); x
[1] 10.4  5.6  3.1  6.4 21.7

Suppose we define r to some value, then it stops working (of course).

sage: r = 2
sage: r
2
sage: x = r([10.4,5.6,3.1,6.4,21.7]); x
Traceback (most recent call last)
...
TypeError: 'sage.rings.integer.Integer' object is not callable

If we reset r, then it works again.

sage: reset('r')
sage: r
R Interpreter
sage: x = r([10.4,5.6,3.1,6.4,21.7]); x
[1] 10.4  5.6  3.1  6.4 21.7
edit flag offensive delete link more

Comments

Thank you for your answer. I am using Sage via CoCalc. When I open a new Sage worksheet and type:

r

x = r([10.4,5.6,3.1,6.4,21.7]); x

I get:

<function r="" at="" 0x7fd8f6b5f5f0="">

Error in lines 1-1 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1013, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_salvus.py", line 2168, in r return r.jupyter_kernel(code,**kwargs) File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_jupyter.py", line 179, in run_code msg_id = kc.execute(code) File "/ext/sage/sage-8.0/local/lib/python2.7/site-packages/jupyter_client/client.py", line 244, in execute raise ...

Kristen Barth gravatar imageKristen Barth ( 2017-12-09 08:28:10 -0500 )edit

... ValueError('code %r must be a string' % code) ValueError: code [10.4000000000000, 5.60000000000000, 3.10000000000000, 6.40000000000000, 21.7000000000000] must be a string

Kristen Barth gravatar imageKristen Barth ( 2017-12-09 08:30:10 -0500 )edit

Ok, when I use https://sagecell.sagemath.org/ it works perfectly fine.

Kristen Barth gravatar imageKristen Barth ( 2017-12-09 09:25:58 -0500 )edit

Please click "help" at the very top of your cocalc worksheet and explain your problem there. The CoCalc team will be able to see the worksheet where you are having problem and to help you out.

slelievre gravatar imageslelievre ( 2017-12-09 11:53:58 -0500 )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: 2017-12-08 11:07:11 -0500

Seen: 169 times

Last updated: Dec 09 '17