34

Questions based on R are much easier to answer if the questioner posts a small example of their data using a function such as dput, so that the answerer can paste the data quickly into their own console. There is a good explanation of why this is necessary here. New users often post images of their data which makes it vastly more difficult to answer the question, along with other issues regarding searchability.

I have noticed now that many users post their data in the form of a formatted table, such as in this question. These tables aren't quite as bad as images, but they are still tricky to paste into your console and make answering the question somewhat annoying. Personally I will avoid any questions where the data is formatted like this.

I was wondering if there would be a way to discourage users to share their data in this format for particular questions (like in R)? Perhaps some kind of tooltip or note under the table tab which suggests it's not a good way to share data?

EDIT: User Larnu points out this applies to questions regarding SQL as well.

EDIT 2: A couple of users seems to have confused exactly why this is an issue. It is not because I have impossibly high standards for how people should format their posts. It is because it is a) potentially error prone and b) time consuming to read in the data from a table. Perhaps unlike questions regarding other languages, it is crucial to have a minimally reproducible example of a dataset in R.

To quote a comment by Chris Schaller:

.. you have to somehow provide that exact data.frame to R, which typically means manually typing out that object (e.g. placing double quotes around strings, commas between values, instantiating the object) and even then you're kinda left guessing as to the class of the object - for example, in the OP's example question, it could be a tibble or a data.frame (or something else), but we're never really sure

Edit3: I just noticed that @KonradRudolph has helpfully pointed out in the comments that the function clipr::read_clip_tbl() very easily allows for the reading in of table presented in data form. I still think it's not ideal since I don't think it accounts for differences in types, but it is a lot easier than trying to copy and paste them directly.

27
  • 5
    You could write a "canned comment", like Peter did in that linked question, telling users how to properly provide the example data.
    – Tom
    Commented Apr 3, 2021 at 14:08
  • 33
    I, personally, don't think this just applies to R. The new tables are awful for SQL based questions too, as converting them to DML statements requires a lot of effort. A fixed width tabular text table, however, is far easier to deal with. The new table markdown is "nice" but it's not always useful unfortunately; sometimes to opposite.
    – Thom A
    Commented Apr 3, 2021 at 14:48
  • 4
    meta.stackexchange.com/a/357335/266284
    – philipxy
    Commented Apr 3, 2021 at 18:42
  • 2
    @Larnu That might be worth pointing out in the editing FAQ as well. I can see someone posting a SQL question with their data in that format only to have someone edit it into the new markdown.
    – BSMP
    Commented Apr 4, 2021 at 7:22
  • 13
    I don't really see a problem with markdown tables in SQL questions. If you copy/paste the table to a text editor, the columns are separated by tabs, which seems just as easy to replace as replacing a pipe symbol. Of course, it would be better if such questions would include DDL and DML scripts. But if the comparison is with pipe separated code-formatted tables, then I don't really see a difference in effort to turn it into a script.
    – trincot
    Commented Apr 4, 2021 at 19:53
  • 3
    I made a userscript to show a button when you hover over tables that lets you copy the table to a CSV format. It works great for me. Only reason I didn't publish it is because I'm a pretty average front-end dev, but if anyone wants to take it and make it better... gist.github.com/WiredUK/26bc458f7ec2d17ae5be8e03ce0c1011
    – DavidG
    Commented Apr 4, 2021 at 21:38
  • 6
    I find that data posted as formatted tables is superior because it enhances the ability to cut and paste into consoles and tool like SSMS and excel, so for SQL I disagree with this post and I want to encourage more users to use formatted tables. It is a deliberate and consitant standard, instead of all the other variants in code blocks. The key for me is that the tables cut'n'paste as tab delimited which is very versatile and even translates well into scripts and consoles. Commented Apr 5, 2021 at 4:53
  • 2
    @ChrisSchaller in R it's kinda annoying because to replicate the issue, you have to somehow provide that exact data.frame to R, which typically means manually typing out that object (e.g. placing double quotes around strings, commas between values, instantiating the object) and even then you're kinda left guessing as to the class of the object - for example, in the OP's example question, it could be a tibble or a data.frame (or something else), but we're never really sure.
    – stevec
    Commented Apr 5, 2021 at 5:06
  • 3
    @stevec I can't comment on R, but for since SQL was brought in it highlights a similar issue, having the data in a table still requires parsing work, you can rarely use it directly, but the table now provides a standard, the underlying syntax can vary a lot, but the formatted output is consistent, meaning once you have learned to use it, it saves a lot of time. It would be awesome if users posted questions with full DDL and DML scripts, but often a the questions asked indicate a level of knowledge that precludes OP from being able to provide this level of detail in the first place. Commented Apr 5, 2021 at 5:14
  • 1
    It's a while since I have done much answering but I think I remember correctly that the markdown tables paste OK into the "text to DDL" box on SQL Fiddle and so allow them to be converted to DDL that way. Commented Apr 5, 2021 at 8:18
  • 5
    Surely the real solution here is to have a flip-out button on the table allowing clipboard copying in various formats. The obvious ones being SQL, R and CSV, but perhaps there are others also Commented Apr 5, 2021 at 9:50
  • 1
    @Charlie "SQL" would probably require multiple flavours. To get multirow insert statements compatible with Oracle and SQL Server for example. Commented Apr 5, 2021 at 10:35
  • 2
    If we have to discourage the most natural form of representing tabular data (a table) then the feature's a bug!
    – Kit
    Commented Apr 5, 2021 at 13:57
  • 1
    @stevec Actually it’s trivial to import HTML tables into R. Commented Apr 6, 2021 at 8:44
  • 1
    @Larnu but that’s not caused by the markdown support for tables. There are tons of poor Java questions containing not a single line of Java code, but a JSON style dump (which has no syntactic support in markdown). People will write bad questions, with syntax support or without.
    – Holger
    Commented Apr 6, 2021 at 12:38

8 Answers 8

13

More generally, there are optimal styles and suboptimal styles for presenting input for several different tags on Stack Exchange sites.

I don't program in R, but I do a lot of PHP and SQL tag pool swimming. I find myself repeatedly asking people to format their:

  • PHP input array/object data as the output from var_export(), because it provides an instantly testable format for volunteers. We often get print_r() or var_dump() or dd() or json_encode()ed data. json_encode()ed data is probably second best, but then if there is no coding attempt, then volunteers will need to make an arbitrary decision about decoding the data as an array or an object.
  • SQL table schemas as table dumps/exports (for the same reason)
  • JavaScript input as JSON

This persistent commenting to request higher quality formats does not scale, is tiresome, and wastes the time that I could be using hammering duplicates answering questions.

I am sure folks that are SMEs in other tags will know the best syntax for fellow volunteers. This is information that serves all users involved. The OP gets faster answers with a higher possibility of correctness and answerers get ready-made data to experiment with and to fuel their online demonstrations.

I think it is appropriate to add something to language tag descriptions which recommends how to provide [MCVE] data and how to express their desired output in an optimal fashion.

This way the community knows the difference between the "good" (instantly usable data), the "bad" (indirectly available data), and the "ugly" (screenshots).

This is not a problem unique to Stack Overflow.

3
  • 3
    This seems like a tooling problem. StackOverflow could build a question form with more structured input boxes, for input, code, output/error, expected output, etc. It could request tabular data to come in a machine readable form (DML, etc.), making it available to people who want to run the code, while still rendering it in a nice readable table for those just reading the question.
    – Alexander
    Commented Apr 5, 2021 at 19:19
  • There are "machine readable forms" that are binary, and so can't be included in a question without requiring some sort of decoding, like base64. I've often thought of the idea of being able to add an attachment to your question. That would solve the problem trivially for reproducibility purposes. Of course, it would be completely unhelpful for human readability of the question, but maybe the use of an attachment feature would require that a text "thumbnail" be supplied as well.
    – CryptoFool
    Commented Apr 5, 2021 at 20:19
  • Could we add a tag-specific MRE page?
    – Shepmaster
    Commented Apr 6, 2021 at 13:37
9

Perhaps in the medium term there can be a Stack Overflow feature that copies these tables in a format that is readable by most languages, for example CSV? I'm thinking about a button that either shows and highlights the corresponding code in a popup, or that directly copies the CSV code ready for pasting into whatever application.

This would combine both the nice readability of tables, and allow them to be exported at low effort for usage in the code.

1
  • That's why I wrote my own userscript
    – DavidG
    Commented Apr 6, 2021 at 8:48
8

I disagree with the premise.

Yes, dput can be useful. But (finally!) having table formatting helps show, well, a formatted table: humans simply read such data better than the output from dput. And your concern about reproducibility is based on an error: importing such data into R isn’t particularly hard. For instance, you could use the read_clip_tbl function from the ‘clipr’ package. Personally I tend not to bother — I’ve got a shortcut function which does the equivalent of read_clip, and pass that to the text argument of read.table (which works well with tables copied from a website).

Of course I can’t force you to use the mechanisms. But that’s on you, not on the person who provides properly formatted data with their reproducible example.

The upshot is: we should encourage people to post properly-formatted tables, not discourage them. For non-tabular data (or where the exact data type is important), dput is still useful (and if the formatted table is insufficient feel free to ask the OP for a data dump). But dput should no longer be the default.

4
  • 2
    Just piggybacking this answer since I clicked into the question from it - why not have both the tabular representation and a way that makes it easier for readers to reproduce the problem? Tabular representations are great for readability... but only readability. So having tabular representations alone isn't ideal, but yeah we shouldn't outright discourage tables. We ought to have the best of both worlds.
    – BoltClock Mod
    Commented Apr 6, 2021 at 9:15
  • @Konrad Thanks for your input. I was not aware of that library - it seems to work well.
    – user438383
    Commented Apr 6, 2021 at 9:17
  • @BoltClock To the extent that this is convenient/necessary (but as I said, it generally isn’t, for R), it should be provided automatically, by the website UI, not require non-obvious, manual work from the question asker. (Some other answers already suggested having a button next to a Markdown table that allows copying the data in various formats.) Commented Apr 6, 2021 at 9:22
  • 1
    @BoltClock I agree -- that's exactly my suggested answer and should be straight-forward to implement.
    – FooBar
    Commented Apr 6, 2021 at 12:59
8

In SQL, users should ideally provide data as DDL/DML statements and not as tables/images.

There are various issues with tabular data that makes it more difficult to answer including:

  1. The answerer has to parse the tabular data and convert it to DDL/DML statements; this increases the burden on the answer and makes it less likely that you will get an answer (particularly if your minimal example has multiple tables or uses more esoteric functionality).
  2. If your tabular data contains date or number columns and your actual DDL statements are storing them as, for example, strings then we cannot see that from the data. Replicating the problem may be impossible without replicating the identical DDL statements and that requires users to provide the DDL/DML statements and not just the data.
  3. Sometimes the problem is not with the code the user is trying to debug; instead it is an issue with the data in their table that results from the DML statements used to insert the data. This can be due to character set issues or implicit casts (typically string to date) and, again, this requires the user's actual DML statements.
4
  • Very much agree. I expect with an increase of DDL/DML statements in sql questions would come a decrease in "try this, it might work" answers. Commented Apr 5, 2021 at 21:10
  • 1
    I would suggest the asker do both, then. From the perspective of someone coming by in the future and trying to figure out whether a question also solves their problem, a table is much easier to read and understand quickly Commented Apr 7, 2021 at 8:07
  • How can this be made practical? E.g., what are some tools for doing this? Commented Jul 4, 2021 at 13:01
  • @PeterMortensen Write a Minimal Representative Example that it demonstrates your SQL problem in a self-contained environment (if you can't create a new one locally then you can use something like db<>fiddle, sqlfiddle or db-fiddle) and then copy-paste everything from that self-contained environment into your question (and then, if you used one, also include a link to the fiddle).
    – MT0
    Commented Jul 4, 2021 at 20:04
5

There is a good explanation of why this is necessary...

Aside from word/acronym mismatch (weproducible?), it’s an explanation of things that could be more useful in getting a good answer, but that does not make any of them necessary as part of asking a question or getting a useful answer. It’s unlikely that someone is going to find that and read all the way through it and understand it before posting their first few questions. Even if they do, the very top answer on that post has a first bullet point saying ...

share a minimal dataset

... which is exactly what the user did in the question used as your example and I think is the thing you are complaining about. It’s something that good questions about databases and data related things should have in them.

@Larnu is talking about the markdown formatting style for tables, not if the user should include tabular data.

Personally I will avoid any questions where the data is formatted like this.

That’s your choice, but I can tell you it feels better and is a more positive experience all around to use an evaluation like "Can I help this person, even a little bit?" rather than "Did this person meet all of my syntax requirements in order to give them assistance?"

7
  • 5
    haha, this is exactly why I try to avoid StackOverflow as much as possible. It is not based on human values. Commented Apr 5, 2021 at 7:19
  • 3
    Speculations like "This code might work" are often discouraged in SE and usually do not help the OP. To have a formatting that helps the answerer (not just one answerer, but a vat majority of them) to recreate and code on top of it in their system. If you are annoyed by the number of "like", "might", "usually" and "vast majority" in this comment, you should realize the answer to bad formatted questions will be equally annoying.
    – nightgaunt
    Commented Apr 5, 2021 at 9:13
  • @nightgaunt - i honestly do not see the relationship between what you are saying and what I said. Can you make the connection(s) for me?
    – StingyJack
    Commented Apr 5, 2021 at 12:17
  • 6
    @StingyJack With all due respect, I feel like you might have missed the point of my post - perhaps because you do not answer questions in R. They shared a minimal dataset, but it was not reproducible. This isn't about me demanding people 'meet all my syntax requirements', it's the difference between me spending 1 second to perfectly replicate their dataset into my console or 5 minutes manually typing it in, possibly screwing it up in the process (i.e. getting the column class wrong). That is why I don't do it, not because I too grumpy or lazy to bother.
    – user438383
    Commented Apr 5, 2021 at 17:27
  • A non reproducible problem or difficult to reproduce problem leads to speculations in answers. It ends up wasting time for both OP as well as the answerer. The comment was my lame attempt to make that point. @user438383 mentioned why it leads to speculations or wrong answers in his comment.
    – nightgaunt
    Commented Apr 6, 2021 at 7:33
  • @nightgaunt - i get what you mean now. ty for explaining.
    – StingyJack
    Commented Apr 6, 2021 at 18:30
  • @user438383 - Avoid false or illogical assertions at the beginning of an idea and there will be less chance of a misunderstanding. Maybe using dput isnt as simple as you think (several hundred questions for [r] how use dput). Have you asked people who use tabular to use dput instead? Do they even know how to do that? I RTM for that command and its not clear how to export test data into an expression using dput. Tables may suck for answering (not disagreeing) but it may be the best the asker can do. 5 minutes of donated time is still a good thing whether you can help 100 or 1.
    – StingyJack
    Commented Apr 6, 2021 at 18:51
1

Ideally users would post example input in an immediately loadable format, but I don't think tables are so awful, given you can easily copy-paste the markdown used to generate them (i.e. a pipe-delimited format) by clicking on the source link of a post (alternatively, clicking 'edit' to view the raw markdown).

e.g. you can easily load the table in your example post with read.table(). You need only remove the first line ---|----|--- (and possibly the first and last columns if leading/trailing pipes were used):

table_str = "| siteID | BirdA | BirdB | BirdC | elevation |
|:-------|:-----:|:-----:|:-----:|:---------:|
|1       | 3     |  2    |   0   |    275    |
|2       | 1     |  5    |   1   |    550    |
|3       | 0     |  0    |   3   |    850    |
|4       | 4     |  3    |   2   |    322    |"

df = read.table(text=table_str, header=TRUE, sep="|")[-1,]

# Remove leading/trailing pipe cols if used in markdown
df = within(df, rm(X, X.1))
2
  • 1
    Sure but at this point we’re quite far from “easily copy-paste”. It requires (completely unnecessary) cleanup work, and the inclusion of the extra row forces the column types to be strings. Commented Apr 6, 2021 at 13:39
  • 1
    @KonradRudolph I think you've misread my answer. I said "you can easily copy-paste the markdown used to generate" the table, as opposed to manually typing each cell like the OP said. It's unnecessary if the user doesn't put leading/trailing pipes (they're not required for common-mark), and so you need no cleanup if they don't do that. But in this example the user did.
    – iacob
    Commented Apr 6, 2021 at 13:53
0

I want to optimise for the lurker, the person who is just here to read the question and the answer. In my mind, tables are great for those reading the posts. I like tables.

9
  • 4
    "tables are great for those reading the posts" Tables are awful for answering these questions. They take almost as much effort to convert to executable code as an image and there are methods of formatting executable code that are just as easy to read as tables for the casual reader and make it much, much easier for the answerer.
    – MT0
    Commented Apr 5, 2021 at 10:23
  • 2
    @MT0 for SQL they don't take much effort to convert - as long as SQL Fiddle is around. I pasted the table from this question into the "Text to DDL" dialogue and it generates CREATE TABLE and INSERT statements for it fine. i.sstatic.net/H6e5G.png Commented Apr 5, 2021 at 10:42
  • 2
    @MartinSmith SQL Fiddle only supports Oracle 11g; there were major enhancements in Oracle 12c which SQL Fiddle does not support (and often SQL Fiddle's Oracle database is not available). DB<>Fiddle and Oracle's LiveSQL do not automatically convert data to tables so saying that one tool supports it when that tool does not support the queries that you need to debug is not helpful and, even if it does work, it then puts the burden onto an external tool.
    – MT0
    Commented Apr 5, 2021 at 10:51
  • 4
    For R, formatted tables won't help the lurker unless they want to know about importing from/exporting to a spreadsheet.
    – Elin
    Commented Apr 6, 2021 at 0:51
  • 2
    @Elin That’s just wrong. Tables help lurkers because they are more readable, and thus make it immediately clear how the tabular data looks like and whether a given question applies to the lurker’s own problem. In fact, this is patently obvious to anybody who has ever read R questions. Claiming the opposite is frankly … bizarre. Commented Apr 6, 2021 at 13:16
  • @KonradRudolph Not if they are using R. The only time data in R looks like that when reading it in is if it is from a spreadsheet. dput outputs are nicely aligned and just as easy to read.
    – Elin
    Commented Apr 6, 2021 at 20:02
  • 1
    @Elin “dput outputs are nicely aligned and just as easy to read.” — That’s nonsense, where are you getting this from?! dput does not aligned its output at all, and it’s definitely not as easy to read as a table. Commented Apr 6, 2021 at 20:18
  • Sorry, followed by a print they print nicely and can be included.
    – Elin
    Commented Apr 6, 2021 at 20:24
  • 1
    @Elin I repeat, that’s simply false (see e.g. here). You’re spreading misinformation. Commented Apr 6, 2021 at 20:40
-4

I was wondering if there would be a way to discourage users to share their data in this format for particular questions

Yes, there is. Downvote and explain why you downvoted.

1
  • 13
    I think downvoting for providing a valid and sensible question, using the tools available, is a bad idea.
    – DavidG
    Commented Apr 5, 2021 at 17:34

You must log in to answer this question.

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