20
$\begingroup$

My question is simply:

What is the preferred way for CV users to share data?

If there isn't one, I think there should be.

For example, some users provide a link to an external data source. Others dump it in code mode. Each has its pros and cons, but at least they are open ways of sharing the data.

Seeing "[...] send me the data through email" a couple of times on CV was the motivation for this question. I hope we – as a community – agree that such behavior should be discouraged.


See also:

$\endgroup$
9
  • 9
    $\begingroup$ I would say code mode is best. Links to other sites may rot away, eg. Our mandate is to develop a permanent repository of high-quality statistical (ML, etc) information in the form of Qs & As. Only having the dataset in the body of the Q really guarantees that. $\endgroup$ Commented May 18, 2018 at 19:06
  • 4
    $\begingroup$ The possibility of sharing data through SE was discussed--and answered in the negative by an SE representative--at stats.meta.stackexchange.com/questions/1035/…. $\endgroup$
    – whuber Mod
    Commented May 18, 2018 at 20:58
  • 4
    $\begingroup$ @whuber Although answered in the negative in the link your provided, I wonder how difficult it would be to create a plug-in that encodes/decodes something .csv files in jpg, gif, or png format? Given the volatile half life of "in the cloud" services, I can see the value in (reasonably sized) data hosting (although... I guess imgur is currently hosting, aren't they?). The issue is having the longevity of Qs & As not depend on the longevity of others' services. $\endgroup$
    – Alexis
    Commented May 18, 2018 at 22:24
  • 8
    $\begingroup$ I don't think that well-established services like gist.github.com are in danger of rotting away before CrossValidated does. $\endgroup$
    – amoeba
    Commented May 19, 2018 at 7:58
  • 4
    $\begingroup$ Alright, thank you for the feedback. Then should this not be written down somewhere... like in the help center: "If you want to share your data, CV prefers you post it in the body of your question (in code mode). If you feel you must use an alternative, we recommend gist.github.com. We do not endorse sharing data through email." Or something along those lines. $\endgroup$
    – Jim
    Commented May 19, 2018 at 16:00
  • 2
    $\begingroup$ Surely the point of repositories such as figshare or dryad is that they won't rot away. Would these be a suitable? I'd argue that this is site is an academic repository of knowledge and as these are academic data sharing sites then they would be a good match. $\endgroup$
    – drstevok
    Commented May 20, 2018 at 12:06
  • 4
    $\begingroup$ One thing I would recommend, particularly if you are using R, is using dput(). $\endgroup$ Commented May 22, 2018 at 13:10
  • $\begingroup$ @Clarinetist may I ask you to you expand your comment as an answer. In the same way @AdamO has done. Could you go into the pros of using dput(). $\endgroup$
    – Jim
    Commented Jun 8, 2018 at 16:14
  • $\begingroup$ @Jim IMO at least, it's honestly simple enough that I don't think an answer would provide any further substantial information. For example, if you have a table in R, doing dput() on the table provides you the raw code used for generating the table, which you can share with anyone else. $\endgroup$ Commented Jun 8, 2018 at 18:49

2 Answers 2

7
$\begingroup$

I'm contributing this as an answer because it's rather hard to share an example in the comments field:

Data of 20 rows or fewer seem fine to share inline. One nice way to share R data (similar to datalines in SAS) is using textConnection. This blends the ease of copy-paste executable code and readable data formats. It also doesn't require any external links (many of which are blocked on more restricted computer networks like mine).

As an example:

mydf <- read.table(textConnection("
 Sepal.Length Sepal.Width Petal.Length Petal.Width Species
          5.1         3.5          1.4         0.2  setosa
          4.9         3.0          1.4         0.2  setosa
          4.7         3.2          1.3         0.2  setosa
          4.6         3.1          1.5         0.2  setosa
          5.0         3.6          1.4         0.2  setosa
          5.4         3.9          1.7         0.4  setosa
"), header=T)
$\endgroup$
1
  • 3
    $\begingroup$ In the same spirit I note that Stata has dataex (bundled with the company's software in Stata 14.2 or 15.1 up, and otherwise downloadable with ssc install dataex). More generally, data examples as text with one header line are highly readable across different software. $\endgroup$
    – Nick Cox
    Commented May 29, 2018 at 17:40
2
$\begingroup$

clarinetist proposed dput() for R users. I also like it a lot. It has the advantage that it outputs all the information a data structure carries, down to the attributes. For instance, in questions about time series analysis, one of the (often) key attributes is the frequency, and this may get lost if a question only gives the time series values.

Specifically, someone may have a question about a dataset. Let's take the built-in AirPassengers dataset as an example. The questioner can simply type

> dput(AirPassengers)

and get the following output, which they simply paste into the question here at CV:

structure(c(112, 118, 132, 129, 121, 135, 148, 148, 136, 119, 
104, 118, 115, 126, 141, 135, 125, 149, 170, 170, 158, 133, 114, 
140, 145, 150, 178, 163, 172, 178, 199, 199, 184, 162, 146, 166, 
171, 180, 193, 181, 183, 218, 230, 242, 209, 191, 172, 194, 196, 
196, 236, 235, 229, 243, 264, 272, 237, 211, 180, 201, 204, 188, 
235, 227, 234, 264, 302, 293, 259, 229, 203, 229, 242, 233, 267, 
269, 270, 315, 364, 347, 312, 274, 237, 278, 284, 277, 317, 313, 
318, 374, 413, 405, 355, 306, 271, 306, 315, 301, 356, 348, 355, 
422, 465, 467, 404, 347, 305, 336, 340, 318, 362, 348, 363, 435, 
491, 505, 404, 359, 310, 337, 360, 342, 406, 396, 420, 472, 548, 
559, 463, 407, 362, 405, 417, 391, 419, 461, 472, 535, 622, 606, 
508, 461, 390, 432), .Tsp = c(1949, 1960.91666666667, 12), class = "ts")

(Note, as above, all the meta information being included at the end.) Then someone contemplating an answer can simply type

AirPassengers <- structure(c(112, 118, 132, 129, 121, 135, 148, 148, 136, 119, ...

and be guaranteed to get the exact data the OP was working on.

Of course the drawback of dput() is that its output is harder to work with for non-R users. However, I for one prefer this over having to read in a tabular structure and fiddling with field types and meta information.

$\endgroup$
2
  • 1
    $\begingroup$ dput will not work for very large datasets. $\endgroup$ Commented Mar 18, 2021 at 16:40
  • $\begingroup$ This is helpful too to people who don't use R routinely, but either you need to edit out a lot of stuff before you can read the data into your own software or you need to open R, run this and then export. In fact the biggest single reason I have R installed is to read data from posts on CV presented this way. The method presented by AdamO is easier for more people. More generally, the first priority here is that data are presentable in a form that people who will answer the questions will read, so that they can post good answers. $\endgroup$
    – Nick Cox
    Commented Mar 30, 2021 at 10:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .