11

I saw this question: Import Excel Files into R. The user has only provided data via a link to Google Drive. Of course this link could disappear and make the question meaningless, so this seems wrong. However, the question is specifically about loading an Excel file (that presumably has features that make it difficult to load). For code and some types of data, there are other ways to provide the required information within the question, but what is the OP supposed to do when it must be an Excel file? Is there a better (more permanent) way for the poster to provide this data?

14
  • 2
    I don't know much about importing Excel data into R, but there should be a way to describe the data and what properties the data has that makes it difficult to import, right? Commented May 18, 2018 at 19:17
  • 3
    Perhaps, but that would not be providing a MCVE. It would require answerers to make their own examples.
    – G5W
    Commented May 18, 2018 at 19:20
  • 1
    Maybe it doesn't apply to Excel data, but if I have a question about doing some operation on an array with one million elements, I don't have to include a one million element array in my question. I can give an example like [1,2,3, ..., 1000000]. Is there no way to describe the properties of the data without including the entire table? Commented May 18, 2018 at 19:52
  • The issue is not about size of the data nor about characteristics of the data itself, but rather about the file format. Really, my question is: what is the poster supposed to do when their problem is tied to a file format rather than the data itself? The OP probably does not even know what the issue is. All (S)He knows is that trying to use a loader built to handle this type of data fails to load the data. That could mean a bug, incorrect use of the tool, failing to follow some constraints on the input, who knows?
    – G5W
    Commented May 18, 2018 at 20:02
  • 1
    Not to mention, an array of values is nothing like an Excel spreadsheet with thousands properties associated to each sheet...
    – Jacob H
    Commented May 18, 2018 at 20:08
  • 3
    As I understand things, if the question is about any generic excel document being imported there is no reason to include a specific document to look at. If the question is about troubles importing a specific document the asker should try and summarize what makes the document difficult to import as concisely as possible. If it is just about the file format itself, looking at an arbitrary set of data doesn't really add any clarification to the question. Commented May 18, 2018 at 20:12
  • Highly relavant: meta.stackexchange.com/questions/73566/… Commented May 18, 2018 at 21:54
  • @psubsee2003 I think that this is not actually relevant. The problem is not about providing some particular data with the question. It is about providing a specific file format.
    – G5W
    Commented May 18, 2018 at 21:58
  • @G5W IMO a question should never be so specific that a specific file is required to demonstrate the problem. If it is that specific, then it isn't useful for anyone else and hence is not a good SO question. A user should be able to provide generic sample data in the question itself to help demonstrate the problem (hence why the table formatting question is relevant) Commented May 18, 2018 at 22:13
  • @psubsee2003 I appreciate your point and do not really disagree. However, I think that if the OP understood what was going on well enough to formulate the general question, he would be able to answer the question. I could easily imagine that given access to the file in question, someone more knowledgeable could provide an answer that explains what is happening more generally and be useful to others. Of course, that depends on the answerers. I agree that on its own the question may be of marginal value.
    – G5W
    Commented May 18, 2018 at 22:39
  • @G5W I guess my point is it should never be necessary to need a specific excel file or other file of specific format. The question should either be able to be generalized to be widely useful (and hence an answer can create the generic file on their own), or the file format should be well known to experts and not require a specific file, or the question is too specific. In essence - accessing a specific file should never be required to answer a question, so a method to access them isn't necessary Commented May 18, 2018 at 22:53
  • @JacobH An Excel file is essentially just a Zip archive that you can browse the same way, but it's also extremely common to use Excel simply as an editor/viewer of .csv files which are perfectly suitable for languages like R or other languages that take simple or complex arrays.
    – TylerH
    Commented May 19, 2018 at 0:39
  • Is base64 a ridiculous suggestion?
    – TRiG
    Commented May 21, 2018 at 8:59
  • 1
    Excel data: stackoverflow.com/questions/32567565/…
    – Cœur
    Commented May 22, 2018 at 15:24

3 Answers 3

13

TL;DR - The question should include the Excel structure as monospace code, but this question is likely a duplicate; see below.


To address your comment, not every question requires an MCVE; an MCVE is required for questions about existing code that does not work. In a question that is more conceptual or broad in nature, an MCVE is not required or really appropriate. It's hard to describe such kinds of questions because these days Stack Overflow is geared so heavily toward questions about existing code that doesn't work, but there remain several other kinds of questions that the Help Center says are on-topic and OK to ask here.

In a question about Excel data, it is not possible to import your data directly, as Stack Overflow does not (yet? Maybe that's too hopeful...) have a Spreadsheet Snippet feature akin to their Stack Snippet feature. Handily, however, spreadsheets of data are essentially a big table, and there is a way to format data to appear like a table:

How to put tables in Stack Overflow?

Is there Markdown to create tables?

Now, despite what your title asks, what you seem to be asking is not really how to visually represent Excel data in a post; it's asking about some aspect of an Excel file's format that is causing problems with R, but looking at his question and his Excel file on Google Drive, his problem is indeed that he has some kind of weird hybrid column header system going on:

enter image description here

In this case, he should post it as monospace code to help identify exactly what his layout is. Something like:

-----------------
- Data - Data 2 -
- Unified Data  -
-----------------
-   a   -   b   -

And so on.

In this particular case, however, the asker's question is, in my opinion, too broad. He's asking for--essentially--a tutorial on how to import Excel code into R, and doesn't explain at all how his code is different or "more complicated" to use his words. He doesn't specify how the output needs to look in R, and he doesn't show any attempt to date of him trying to import the data into R... so we don't know what his attempt looks like, or if he has even made one.

Most helpfully, however, is that this question is likely a duplicate of Read csv with two headers into a data.frame or of Reading two-line headers in R. A cursory google search also turns up a half-dozen other similar questions, as well.

3
  • 1
    Excellent: works as an answer to this Meta question and to the trigger SO question as well.
    – APC
    Commented May 19, 2018 at 7:17
  • 1
    I would not trust anyone to manually reproduce that table structure in ASCII-art formatting. Even in your tiny example, there's no border between the Data - Data 2 bit and the Unified Data bit, making it hard to see what the structure is intended to be. Unless there's some tool that parses this format, I don't see any benefit to being able to copy-paste it, and it doesn't seem to be useful for searches either, so I think a screenshot is probably more useful. Commented May 20, 2018 at 19:14
  • 1
    @user2357112 My example was just a 50,000 foot view to illustrate how to format a table. It should be trivial to extrapolate from that and recreate the table structure in the screenshot, I just did not want to expend the time to do so. I agree a screenshot is probably as useful, but there is a stigma against pasting data via screenshots here; my suggestion was given with that stigma in mind.
    – TylerH
    Commented May 20, 2018 at 20:05
4

My current comment prompt for input and/or output sample data is to provide the OP with the following procedure:

  1. Copy some sample data from Excel
  2. Go to https://www.tablesgenerator.com/markdown_tables
  3. Paste the data (File -> Paste table data)
  4. Click Generate.
  5. Click Copy to clipboard
  6. Paste the Markdown table into the question.

This works very well, for the most part; aside from merged cells, which AFAICT aren't really handled ATM by CommonMark.

Ideally, SE should implement something similar without resorting to a third-party website.

2
1

In addition to the accepted answer, something worthy of comment is the fact that if you paste tab-separated spaces into a excel cell, it will be pasted in the corresponding cells, assuming there are no row-spans or col-spans. So posting a monospaced version of the dataset (if it's not too long) will suffice

You must log in to answer this question.

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