An open API service indexing awesome lists of open source software.

https://github.com/maurolepore/loaddata

Load external data from a .csv file into a data frame (5' training for The Carpentries)
https://github.com/maurolepore/loaddata

carpentries carpentry instructors r rmarkdown training

Last synced: 12 months ago
JSON representation

Load external data from a .csv file into a data frame (5' training for The Carpentries)

Awesome Lists containing this project

README

          

---
title: "Load external data from a .csv file into a data frame"
output:
github_document:
toc: true
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = TRUE,
comment = "#>",
collapse = TRUE
)
```

---

## See https://bit.ly/carpentry-slides

## Try by intuition

Document what you did.

```{r}
# Some code goes here

```

# Back to the lesson

> To download the data into the data/ subdirectory, run the following:

WARNING: This will fail. Why? (Run and read the error message)

Hint:
* Look in the Files tab. What's missing?
* What are the first two arguments of `download.file()`?
* Find out with the help of autocompletion (press TAB) or with `?`

```{r download-problem, error=TRUE}
# MISTERY-FUNCTION-GOES-HERE("data")

download.file(
"https://ndownloader.figshare.com/files/2292169",
"data/portal_data_joined.csv"
)
```

```{r download-solution, echo=FALSE}
# MISTERY-FUNCTION-GOES-HERE("data")
# TODO REMOVE
dir.create("data")

download.file(
"https://ndownloader.figshare.com/files/2292169",
"data/portal_data_joined.csv"
)
```

> You are now ready to load the data:

```{r}
surveys <- read.csv("data/portal_data_joined.csv")
```

> Print the variable's value: `surveys`

```{r, eval=FALSE}
# WARNING: In the console, this prints looooong output
surveys
```

> Let's check the top (the first 6 lines) of this data frame using the function `head()`:

```{r}
head(surveys)
```

# Thank you

* https://bit.ly/carpentry-slides
* https://bit.ly/mauro_lepore