Ask Your Question
1

inter-mixing Sage and R

asked 2011-07-14 18:51:21 +0100

anonymous user

Anonymous

updated 2011-07-15 13:49:36 +0100

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?

edit retag flag offensive close merge delete

Comments

parzan gravatar imageparzan ( 2011-07-15 07:07:22 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2011-07-29 15:46:08 +0100

kcrisman gravatar image

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

edit flag offensive delete link more

Comments

When I type "r.read_table?" or "r.read_csv?" I have an attribute error.

debian_economist gravatar imagedebian_economist ( 2016-08-24 17:20:05 +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: 2011-07-14 18:51:21 +0100

Seen: 712 times

Last updated: Jul 29 '11