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.Wed, 24 Aug 2016 10:20:05 -0500inter-mixing Sage and Rhttp://ask.sagemath.org/question/8229/inter-mixing-sage-and-r/Updated: How well is compatibility with intermixing Sage code and R code?
For instance, if I want to do:
f = r.read.table("bar.txt", row.names = NULL, header=T, sep=";")
calling some sage function and prints some output
but it didn't work as Sage can't find the corresponding R "table" method.
But I do %r and just use "read.table(...)", it works flawlessly. But I can't use the pass the R timeseries to Sage list.
Is there a better way around this?
Thu, 14 Jul 2011 11:51:21 -0500http://ask.sagemath.org/question/8229/inter-mixing-sage-and-r/Comment by parzan for <p>Updated: How well is compatibility with intermixing Sage code and R code?
For instance, if I want to do:</p>
<p>f = r.read.table("bar.txt", row.names = NULL, header=T, sep=";")
calling some sage function and prints some output</p>
<p>but it didn't work as Sage can't find the corresponding R "table" method.
But I do %r and just use "read.table(...)", it works flawlessly. But I can't use the pass the R timeseries to Sage list.</p>
<p>Is there a better way around this?</p>
http://ask.sagemath.org/question/8229/inter-mixing-sage-and-r/?comment=21467#post-id-21467About the second question, check http://ask.sagemath.org/question/315/how-to-use-r-with-sage.Fri, 15 Jul 2011 00:07:22 -0500http://ask.sagemath.org/question/8229/inter-mixing-sage-and-r/?comment=21467#post-id-21467Answer by kcrisman for <p>Updated: How well is compatibility with intermixing Sage code and R code?
For instance, if I want to do:</p>
<p>f = r.read.table("bar.txt", row.names = NULL, header=T, sep=";")
calling some sage function and prints some output</p>
<p>but it didn't work as Sage can't find the corresponding R "table" method.
But I do %r and just use "read.table(...)", it works flawlessly. But I can't use the pass the R timeseries to Sage list.</p>
<p>Is there a better way around this?</p>
http://ask.sagemath.org/question/8229/inter-mixing-sage-and-r/?answer=12542#post-id-12542This may not completely answer your question, but note that dot methods in R become underscores in Sage.
sage: r.read[tab]
r.read r.read_csv r.read_ftable
r.readBin r.read_csv2 r.read_fwf
r.readChar r.read_dcf r.read_socket
r.readCitationFile r.read_delim r.read_table
r.readLines r.read_delim2 r.read_table_url
r.read_DIF r.read_fortran r.readline
sage: r.read_table?
<snip>
Definition: r.read_table(self, *args, **kwds)
Docstring:
read.table package:utils R Documentation
Data Input
Description:
Reads a file in table format and creates a data frame from it,
with cases corresponding to lines and variables to fields in the
file.
Usage:
read.table(file, header = FALSE, sep = "", quote = "\"'",
dec = ".", row.names, col.names,
as.is = !stringsAsFactors,
na.strings = "NA", colClasses = NA, nrows = -1,
I don't have your bar.txt, though, and unfortunately passing optional arguments can be tricky, sometimes calling for multiple levels of quotes, sometimes not. I've often used `r.eval("R command")` for that, like
r.eval('zsummin(loca.p(c(%s),c(%s),c(%s)),max.iter=400,algorithm="\%s")'%(str(exes)[1:-1],str(whys)[1:-1],str(prof)[1:-1],algorithm))
which however is not ideal, but it gets the job done.
Fri, 29 Jul 2011 08:46:08 -0500http://ask.sagemath.org/question/8229/inter-mixing-sage-and-r/?answer=12542#post-id-12542Comment by debian_economist for <p>This may not completely answer your question, but note that dot methods in R become underscores in Sage.</p>
<pre><code>sage: r.read[tab]
r.read r.read_csv r.read_ftable
r.readBin r.read_csv2 r.read_fwf
r.readChar r.read_dcf r.read_socket
r.readCitationFile r.read_delim r.read_table
r.readLines r.read_delim2 r.read_table_url
r.read_DIF r.read_fortran r.readline
sage: r.read_table?
<snip>
Definition: r.read_table(self, *args, **kwds)
Docstring:
read.table package:utils R Documentation
Data Input
Description:
Reads a file in table format and creates a data frame from it,
with cases corresponding to lines and variables to fields in the
file.
Usage:
read.table(file, header = FALSE, sep = "", quote = "\"'",
dec = ".", row.names, col.names,
as.is = !stringsAsFactors,
na.strings = "NA", colClasses = NA, nrows = -1,
</code></pre>
<p>I don't have your bar.txt, though, and unfortunately passing optional arguments can be tricky, sometimes calling for multiple levels of quotes, sometimes not. I've often used <code>r.eval("R command")</code> for that, like</p>
<pre><code>r.eval('zsummin(loca.p(c(%s),c(%s),c(%s)),max.iter=400,algorithm="\%s")'%(str(exes)[1:-1],str(whys)[1:-1],str(prof)[1:-1],algorithm))
</code></pre>
<p>which however is not ideal, but it gets the job done.</p>
http://ask.sagemath.org/question/8229/inter-mixing-sage-and-r/?comment=34570#post-id-34570When I type "r.read_table?" or "r.read_csv?" I have an attribute error.Wed, 24 Aug 2016 10:20:05 -0500http://ask.sagemath.org/question/8229/inter-mixing-sage-and-r/?comment=34570#post-id-34570