-
Notifications
You must be signed in to change notification settings - Fork 7
/
README.Rmd
77 lines (50 loc) · 1.6 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, eval = FALSE)
```
## rmd2jupyter
Convert rmarkdown (.Rmd) files into jupyter notebooks (.ipynb).
### Example
Create a .Rmd file.
```{r rmd}
rmd <- "# Module 1. Working with web APIs
## Gathering publicly available web data
The two most common ways to collect publicly available web data are (1) web scraping and (2) interacting with Application Program Interfaces (API).
## Web scraping
- A normal workflow goes something like this
- Extract website source code, known as Extensible Markup Language (XML). XML is similar to HTML only designed for storing not displaying data.
- Although XML trees contain elements, tags, and text, data collected via web scraping is almost always unstructred
### Web scraping in R
- I recommend the {rvest} package.
\`\`\`{r}
library(rvest)
## population statistics
population_url <- \"https://en.wikipedia.org/wiki/List_of_countries_by_population_(United_Nations)\"
## read in page
pop <- read_html(population_url)
\`\`\`"
## save as temp file
tmp <- tempfile(fileext = ".Rmd")
cat(rmd, file = tmp)
## render html
rmarkdown::render(tmp)
## output output
browseURL(gsub("\\.Rmd$", ".html", tmp))
```
#### Rmd -> html
Screen capture of output.
![](tools/readme/ss_rmd.png)
#### Rmd -> ipynb.
Now convert to an ipython notebook.
```{r}
## install and load rmd2jupyter
devtools::install_github("mkearney/rmd2jupyter")
library(rmd2jupyter)
## convert
rmd2jupyter(tmp)
## open via your jupyter notebook method
```
Screen capture of jupyter notebook.
![](tools/readme/ss_ipynb.png)