Re: [R] skeleton for C code?

From: Douglas Bates <bates_at_stat.wisc.edu>
Date: Wed, 27 Jun 2007 21:20:12 -0500

On 6/27/07, ivo welch <ivowel_at_gmail.com> wrote:
> Dear R experts---I would like to write a replacement for the read.csv
> function that is less general, but also more efficient.
>
> could someone please provide me with a skeleton function that shows me
> how to read the arguments and return a data frame for a call to a C
> function that handles
>
> returned.data.frame = my.read.csv(file, header = TRUE, sep = ",",
> quote="\"", dec=".",
> fill = TRUE, comment.char="", ...)
>
> this may be very difficult, of course, in which case writing such a
> function would not be worth it. I guess I would be happy just to
> learn how to return a basic data frame that holds data vectors that
> are either strings or numbers---nothing more complex.
>
> help appreciated.

Should we assume that you have already read the relevant sections of the manual "Writing R Extensions"?

The .Call interface is the easiest way to return an object like a data frame. I might pass the result back as a list and use something like

do.call(data.frame, .Call("my_csv_reader", file, ...))

rather than duplicating all the error checking that is done in the data.frame function.



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 28 Jun 2007 - 02:34:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 28 Jun 2007 - 03:32:40 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.