This article describes how to import an Excel or CSV data set into Displayr using R.
Requirements
- An Excel (.xls, .xslx, .csv) data set saved as online. In this example, we have a raw data table of correlation scores saved on a website and in cloud storage.
- An URL (link) to the Excel files.
- A Displayr document.
Method 1 - DownloadXLSX R package
1. Go to Data Sources > Plus (+) > R.
2. Enter a name for the data set under Name.
3. Update and input the below R code where it states "Enter your R code here":
library(flipAPI)
DownloadXLSX("https://wiki.q-researchsoftware.com/images/b/b9/Cola_Discriminant_Functions.xlsx", sheet = 2, range = "A2:G329")
Note, this function allows for referencing specific sheets and the exact cell range.
You will need to update the above code and replace the URL link, Excel sheet, and cell range references.
Method 2 - httr R package
1. Go to Data Sources > Plus (+) > R.
2. Enter a name for the data set under Name.
3. Update and input the below R code where it states "Enter your R code here":
library(httr)
url = "https://docs.google.com/spreadsheets/d/XYZ123/export?format=csv"
link = GET(url)
data = content(link)
In this example, we have the same data stored in a Google Sheet document. Here, we use httr's content function to return the data from the GET request. Note, it is important to append "/export?format=csv" to the URL so it will download automatically as a data set.
You will need to update the above code and replace the URL link.