Re: [R] function to export data

From: Paul Hiemstra <p.hiemstra_at_geo.uu.nl>
Date: Mon, 30 Jun 2008 11:22:27 +0200

Hi Daniel,

You did not make clear why you want to export the data. If you want to export data to another program the usual way to export data to a text file is through the use of write.table(). Something along the lines of:

summary(cars) # cars is a standard R dataset write.table(summary(cars), file = "dataexp.txt") ?write.table

If you want to store R data to read it back into R again I would recommend the save() option in combination with the load option. Example:

x = summary(cars)
save(x, file = "dataexp.rda") # The extension of the file is not really important

# Load a new R session
load("dataexp.rda") # This makes the object "x" available in the new session

cheers,

Paul

Daniel Pires wrote:
>
>
> Hi,
>
>
>
> Iím trying to built a simple function that allows me to export
> automatically some results to a text file. Iíve tried the two following
> approaches but none worked.
>
>
>
>
>> exportdata<-function(x) {
>>
>
> + dataexp<-summary(x)
>
> + export(dataexp,type="ascii",file="dataexp.txt")
>
> + }
>
>
>> exportdata(glm.poisson0)
>>
>
> Error in eval(expr, envir, enclos) : object "dataexp" not found
>
>
>
>
>
>
>
> exportdata2<-function(x) {
>
> sink("exportdata2.txt")
>
> summary(x)
>
> sink()
>
> }
>
>
>
>
>> exportdata2(glm.poisson0) # the file is created but with no data in it.
>>
>
>
>
>
>
> Can anyone give me some hints on what Iím missing here? I would be very
> grateful for that.
>
>
>
> Thanks.
>
>
>
>
>
> Daniel Pires
>
>
>
>
>
> Daniel Pires
>
> Faculdade de CiÍncias da Universidade de Lisboa
>
> Dep. Biologia Animal
>
> Ed. C2, piso 2
>
> Campo Grande 1749-016 Lisboa
>
> Portugal
>
> <http://ffishgul.fc.ul.pt/> http://ffishgul.fc.ul.pt/
>
>
>
>
> [[alternative HTML version deleted]]
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> R-help_at_r-project.org 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.
>

-- 
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone: 	+31302535773
Fax:	+31302531145
http://intamap.geo.uu.nl/~paul

______________________________________________
R-help_at_r-project.org 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 Mon 30 Jun 2008 - 09:26:20 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 Mon 30 Jun 2008 - 10:31:54 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.

list of date sections of archive