knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Vignettes are long form documentation commonly included in packages. Because they are part of the distribution of the package, they need to be as compact as possible. The html_vignette output type provides a custom style sheet (and tweaks some options) to ensure that the resulting html is as small as possible. The html_vignette format:

Vignette Info

Note the various macros within the vignette section of the metadata block above. These are required in order to instruct R how to build the vignette. Note that you should change the title field and the \VignetteIndexEntry to match the title of your vignette.

Styles

The html_vignette template includes a basic CSS theme. To override this theme you can specify your own CSS in the document metadata as follows:

output: 
  rmarkdown::html_vignette:
    css: mystyles.css

Figures

The figure sizes have been customised so that you can easily put two images side-by-side.

plot(1:10)
plot(10:1)

You can enable figure captions by fig_caption: yes in YAML:

output:
  rmarkdown::html_vignette:
    fig_caption: yes

Then you can use the chunk option fig.cap = "Your figure caption." in knitr.

More Examples

You can write math expressions, e.g. $Y = X\beta + \epsilon$, footnotes^[A footnote here.], and tables, e.g. using knitr::kable().

knitr::kable(head(mtcars, 10))

Also a quote using >:

"He who gives up [code] safety for [code] speed deserves neither." (via)

The rgeizhals package: Highlevel functionality

The rgheizhals package can be used to scrape category listings from a specific product category on https://geizhals.at/, including the links to the detailed product info pages.

To use the package, navigate to a specific geizhals page by selecting the appropriate page in the sidebar of the page (1) and then choosing a category that should be scraped (2).

knitr::include_graphics(path = "./img/geizhals-mainpage.jpg")

Furthermore, it is advised that the choices displayed on the page are limited by choosing the filters (3) that are appropriate for the search in question. This helps to avoid being banned (temporarily) from the geizhals page for issuing too many requests.

Once the listing page contains the information that should be scraped, the url can be copied from the browser.

library(rvest)
library(stringr)
library(rgeizhals)
library(dplyr)


## first, define filters on geizhals.
## then, get url:
url_gh <- "https://geizhals.at/?cat=umtsover&xf=11111_6.0~148_Android~157_16384~2392_5.0~2607_1536"

The next step is to use the get_geizhals_data() function. It is good practice to use the max_pages argument to limit the number of category pages that are scraped. Additionally, it is also possible to use the max_items argument, which limits the number of detail pages that are scraped.

dat_gh <- get_geizhals_data(url_gh, max_pages = 3)
Fetching listing page 1...
Fetching listing page 2...
Fetching listing page 3...
Done.
Fetching detailpage https://geizhals.at/emporia-smart-2-blau-a1741823.html?hloc=at...
Fetching detailpage https://geizhals.at/caterpillar-cat-s60-schwarz-a1395802.html?hloc=at...
Fetching detailpage https://geizhals.at/sony-xperia-m5-schwarz-a1305403.html?hloc=at...
Fetching detailpage https://geizhals.at/xiaomi-redmi-4x-32gb-schwarz-a1585638.html?hloc=at...
dat_gh <- get_geizhals_data(url_gh, max_pages = 3)
saveRDS(dat_gh, file = "/Users/in186000/data-nth-sync/leisure/r-packages/rgeizhals/inst/extdata/dat_vignette.rds")
dat_gh <- readRDS(system.file("extdata", "dat_vignette.rds", package = "rgeizhals"))
head(dat_gh)


ingonader/rgeizhals documentation built on May 29, 2019, 3:05 a.m.