I was preparing an e-mail for the help list and ran across a quandary. When asking for help it is useful to include the code/data so others can run your code and test it. I was running code on a data frame and wanted to include a small version of the data frame. The data frame was based on experimental data. What is the best way to do this? I didn't want to send an attachment so a wrote code to generate the data frame but it was a bit cumbersome. Everything worked as planned but then I saw my error and never had to send to e-mail (perhaps there is hope for me yet). Is there an easier way to export a SMALL data frame so you can recreate it using the example code that can be placed in the posting guide? Is it really a good idea to show people how to do this as we run the risk of someone sending a huge e-mail? Perhaps the "manual method" is really the best way to go, submitted for your consideration. Michael J. Bock, PhD. ARCADIS 24 Preble St. Suite 100 Portland, ME 04101 207.828.0046 fax 207.828.0062 [[alternative HTML version deleted]]
Michael J. Bock wrote:> I was preparing an e-mail for the help list <snip><snip><snip> ... > <snip><snip><snip> Everything worked as planned but then I saw my > error and never had to send the e-mail.This is one of the many great advantages of following the posting guide and framing a clear and well formulated question. Doing so reveals the answer to the question, more often than not. cheers, Rolf Turner rolf at math.unb.ca
On Thursday 21 April 2005 09:09, Bock, Michael wrote:> I was preparing an e-mail for the help list and ran across a > quandary. When asking for help it is useful to include the code/data > so others can run your code and test it. I was running code on a data > frame and wanted to include a small version of the data frame. The > data frame was based on experimental data. What is the best way to do > this? I didn't want to send an attachment so a wrote code to generate > the data frame but it was a bit cumbersome. Everything worked as > planned but then I saw my error and never had to send to e-mail > (perhaps there is hope for me yet). Is there an easier way to export > a SMALL data frame so you can recreate it using the example code that > can be placed in the posting guide?I believe this is already covered. Here's what the guide has to say: """ When providing examples, it is best to give an R command that constructs the data, as in the matrix() expression above. For more complicated data structures, dump("x", file=stdout()) will print an expression that will recreate the object x. """ -Deepayan
You can use 'dput()' or 'dump()' to create a text representation and paste that into an email if it's small enough. Another possiblity, if you have access to a webserver, is to save a workspace file via 'save()' or 'save.image()' and post it on the web. Given the URL, users with Internet access can 'load()' it directly off the web into R. I guess one downside of that method is the example data do not get stored in the mailing list archives. -roger Bock, Michael wrote:> I was preparing an e-mail for the help list and ran across a quandary. > When asking for help it is useful to include the code/data so others can > run your code and test it. I was running code on a data frame and wanted > to include a small version of the data frame. The data frame was based > on experimental data. What is the best way to do this? I didn't want to > send an attachment so a wrote code to generate the data frame but it was > a bit cumbersome. Everything worked as planned but then I saw my error > and never had to send to e-mail (perhaps there is hope for me yet). Is > there an easier way to export a SMALL data frame so you can recreate it > using the example code that can be placed in the posting guide? Is it > really a good idea to show people how to do this as we run the risk of > someone sending a huge e-mail? Perhaps the "manual method" is really the > best way to go, submitted for your consideration. > > > Michael J. Bock, PhD. > ARCADIS > 24 Preble St. Suite 100 > Portland, ME 04101 > 207.828.0046 > fax 207.828.0062 > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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 >-- Roger D. Peng http://www.biostat.jhsph.edu/~rpeng/
On 4/21/05, Bock, Michael <MBock at arcadis-us.com> wrote:> Is there an easier way to export a SMALL data frame so you can recreate it > using the example code that can be placed in the posting guide? Is it > really a good idea to show people how to do this as we run the risk of > someone sending a huge e-mail? Perhaps the "manual method" is really the > best way to go, submitted for your consideration.head will pick off the first few rows and dput will output it in a format that can be pasted back into a session, e.g.> data(iris) > irish <- head(iris) > dput(irish)structure(list(Sepal.Length = c(5.1, 4.9, 4.7, 4.6, 5, 5.4), Sepal.Width = c(3.5, 3, 3.2, 3.1, 3.6, 3.9), Petal.Length = c(1.4, 1.4, 1.3, 1.5, 1.4, 1.7), Petal.Width = c(0.2, 0.2, 0.2, 0.2, 0.2, 0.4), Species = structure(c(1, 1, 1, 1, 1, 1), .Label c("setosa", "versicolor", "virginica"), class = "factor")), .Names = c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "Species"), row.names = c("1", "2", "3", "4", "5", "6"), class = "data.frame")