ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 10 Dec 2017 20:08:29 +0100r.xyz isn't working anymore? (R Project)https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/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?Fri, 08 Dec 2017 18:07:11 +0100https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/Comment by vdelecroix for <p>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?</p>
https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?comment=40022#post-id-40022We 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?Fri, 08 Dec 2017 22:04:39 +0100https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?comment=40022#post-id-40022Comment by tmonteil for <p>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?</p>
https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?comment=40023#post-id-40023+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.7Fri, 08 Dec 2017 23:58:05 +0100https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?comment=40023#post-id-40023Comment by slelievre for <p>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?</p>
https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?comment=40087#post-id-40087Thanks for reporting this bug. This bug is now tracked at
[https://github.com/sagemathinc/cocalc/issues/2564](https://github.com/sagemathinc/cocalc/issues/2564) .Sun, 10 Dec 2017 20:08:29 +0100https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?comment=40087#post-id-40087Answer by slelievre for <p>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?</p>
https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?answer=40027#post-id-40027When Sage starts, `r` is predefined as the R interpreter.
(Edit: this does not seem to be the case in CoCalc.)
In a new Sage session, with `r` predefined as above, 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
If in such a Sage session we assign some other value to `r`,
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
To set `r` to be the R interpreter, whether the Sage
being used predefines `r` that way or not, use:
sage: from sage.interfaces.r import r
In a Sage session where `r` was initially the R interpreter,
but was then redefined to be something else, this can also
be used, instead of `reset('r')`, to restore `r` as the R interpreter.Sat, 09 Dec 2017 07:45:44 +0100https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?answer=40027#post-id-40027Comment by Kristen Barth for <p>When Sage starts, <code>r</code> is predefined as the R interpreter.</p>
<p>(Edit: this does not seem to be the case in CoCalc.)</p>
<p>In a new Sage session, with <code>r</code> predefined as above, the following works:</p>
<pre><code>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
</code></pre>
<p>If in such a Sage session we assign some other value to <code>r</code>,
then it stops working (of course).</p>
<pre><code>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
</code></pre>
<p>If we reset <code>r</code>, then it works again.</p>
<pre><code>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
</code></pre>
<p>To set <code>r</code> to be the R interpreter, whether the Sage
being used predefines <code>r</code> that way or not, use:</p>
<pre><code>sage: from sage.interfaces.r import r
</code></pre>
<p>In a Sage session where <code>r</code> was initially the R interpreter,
but was then redefined to be something else, this can also
be used, instead of <code>reset('r')</code>, to restore <code>r</code> as the R interpreter.</p>
https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?comment=40035#post-id-40035... ValueError('code %r must be a string' % code)
ValueError: code [10.4000000000000, 5.60000000000000, 3.10000000000000, 6.40000000000000, 21.7000000000000] must be a stringSat, 09 Dec 2017 15:30:10 +0100https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?comment=40035#post-id-40035Comment by Kristen Barth for <p>When Sage starts, <code>r</code> is predefined as the R interpreter.</p>
<p>(Edit: this does not seem to be the case in CoCalc.)</p>
<p>In a new Sage session, with <code>r</code> predefined as above, the following works:</p>
<pre><code>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
</code></pre>
<p>If in such a Sage session we assign some other value to <code>r</code>,
then it stops working (of course).</p>
<pre><code>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
</code></pre>
<p>If we reset <code>r</code>, then it works again.</p>
<pre><code>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
</code></pre>
<p>To set <code>r</code> to be the R interpreter, whether the Sage
being used predefines <code>r</code> that way or not, use:</p>
<pre><code>sage: from sage.interfaces.r import r
</code></pre>
<p>In a Sage session where <code>r</code> was initially the R interpreter,
but was then redefined to be something else, this can also
be used, instead of <code>reset('r')</code>, to restore <code>r</code> as the R interpreter.</p>
https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?comment=40034#post-id-40034Thank 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 ...Sat, 09 Dec 2017 15:28:10 +0100https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?comment=40034#post-id-40034Comment by Kristen Barth for <p>When Sage starts, <code>r</code> is predefined as the R interpreter.</p>
<p>(Edit: this does not seem to be the case in CoCalc.)</p>
<p>In a new Sage session, with <code>r</code> predefined as above, the following works:</p>
<pre><code>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
</code></pre>
<p>If in such a Sage session we assign some other value to <code>r</code>,
then it stops working (of course).</p>
<pre><code>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
</code></pre>
<p>If we reset <code>r</code>, then it works again.</p>
<pre><code>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
</code></pre>
<p>To set <code>r</code> to be the R interpreter, whether the Sage
being used predefines <code>r</code> that way or not, use:</p>
<pre><code>sage: from sage.interfaces.r import r
</code></pre>
<p>In a Sage session where <code>r</code> was initially the R interpreter,
but was then redefined to be something else, this can also
be used, instead of <code>reset('r')</code>, to restore <code>r</code> as the R interpreter.</p>
https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?comment=40037#post-id-40037Ok, when I use https://sagecell.sagemath.org/ it works perfectly fine.Sat, 09 Dec 2017 16:25:58 +0100https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?comment=40037#post-id-40037Comment by slelievre for <p>When Sage starts, <code>r</code> is predefined as the R interpreter.</p>
<p>(Edit: this does not seem to be the case in CoCalc.)</p>
<p>In a new Sage session, with <code>r</code> predefined as above, the following works:</p>
<pre><code>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
</code></pre>
<p>If in such a Sage session we assign some other value to <code>r</code>,
then it stops working (of course).</p>
<pre><code>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
</code></pre>
<p>If we reset <code>r</code>, then it works again.</p>
<pre><code>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
</code></pre>
<p>To set <code>r</code> to be the R interpreter, whether the Sage
being used predefines <code>r</code> that way or not, use:</p>
<pre><code>sage: from sage.interfaces.r import r
</code></pre>
<p>In a Sage session where <code>r</code> was initially the R interpreter,
but was then redefined to be something else, this can also
be used, instead of <code>reset('r')</code>, to restore <code>r</code> as the R interpreter.</p>
https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?comment=40040#post-id-40040Please 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.Sat, 09 Dec 2017 18:53:58 +0100https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?comment=40040#post-id-40040Answer by Harald Schilly for <p>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?</p>
https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?answer=40042#post-id-40042Hello, 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-73ea-4921-80e9-0a5d792fc511/r-interpreter.sagews?viewer=shareSat, 09 Dec 2017 19:07:39 +0100https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?answer=40042#post-id-40042Comment by Kristen Barth for <p>Hello, the <code>r</code> in CoCalc's Sage Worskheets is different from the <code>r</code> in Sage itself. The reason is that <code>%r</code> at the top of a cell launches the execution in an R jupyter kernel. Different philosophy altogether.</p>
<p>However, you can do <code>r = R()</code> in a sagews which creates and defines the same R-interpreter <code>r</code>.</p>
<pre><code>r = R()
r.summary(r([1,2,3,2]))
</code></pre>
<p><a href="https://cocalc.com/share/20e4a191-73ea-4921-80e9-0a5d792fc511/r-interpreter.sagews?viewer=share">https://cocalc.com/share/20e4a191-73e...</a></p>
https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?comment=40047#post-id-40047Thank you!Sat, 09 Dec 2017 21:20:04 +0100https://ask.sagemath.org/question/40017/rxyz-isnt-working-anymore-r-project/?comment=40047#post-id-40047