0

I created a rmarkdown html document to share code from an analysis in R. I'd like to include the data as well, but I am not sure of the most convenient way (for the recipient) of providing data. I can embed a CSV as a URI data scheme like this:

<a download="HUGEvirus.csv" href="`r sprintf('data:text/csv; base64,%s', encoded)`">Download data as CSV</a>

or provide an HTML table that could range from raw to fancy:

```{r echo=FALSE}
knitr::kable(iris)
```

I am sure there are other options as well. Assuming the dataset has similar dimensions to datasets::iris, how can I share a dataset that:

-is accessible from most platforms/software
-can be easily read into R
-can be packaged with rmarkdown document containing code ie single file to share
-is the smallest file size

What if dimensions of the dataset are 100x larger?

Skaqqs
  • 4,010
  • 1
  • 7
  • 21
  • 1
    How exactly are you defining "best"? As currently worded, this question seems opinion-based which is considered off-topic for Stack Overflow. Perhaps you could edit to make it easier to provide answers that can be tested to meet your specific requirements. – MrFlick Jul 02 '18 at 14:24
  • 1
    Here you have a few options: https://cran.r-project.org/web/packages/kableExtra/vignettes/awesome_table_in_html.html#conditional_logic – RLave Jul 02 '18 at 14:27
  • I edited the post to provide criteria @MrFlick – Skaqqs Jul 02 '18 at 15:00
  • Do you want the data to be visible in the document, or is it enough for it to be embedded in the HTML code? Does it really need to be in the document - especially in the "100x larger" case hosting the data somewhere online seems much easier. Post it on (github|dropbox|onedrive|google drive|whatever else you like) and put a link in the document. – Gregor Thomas Jul 02 '18 at 15:02

1 Answers1

1

Check DT::datatable. Using in a rmarkdown / html_output and printing table with extensions = 'buttons'. Check this https://rstudio.github.io/DT/extensions.html

Plotting data in a DT::datatable with extensions of buttons, will allow user to download select or all data in CSV/excel (when opened in Chrome).

This will help: - user get data - data is again readable by r due to excel/csv - can be used for large datasets ( I have tried for 60,000+ records) - code can be shared via chunk options echo=TRUE

Hope this helps. Cannot share a sample but if you share some data with desired output, we can test. Cheers!!

anuanand
  • 400
  • 1
  • 9