Some frequently used functions for working with Blogdown/Hugo

Undocumented; just a collection of helpful functions, yet.

Blogdown Handling

Render with visibility in local network

blogdown::serve_site(host = '0.0.0.0')

regular preview

blogdown::serve_site()

Stop Server & restart R-Session if needed

blogdown::stop_server()
.rs.restartR()

Publishing

blogdown::hugo_build()

Default Settings (.Rprofile)

put these options in your .Rprofile (user or project)+ newline \n (a la git)

file.edit("~/.Rprofile")
options(servr.daemon = TRUE)
options(blogdown.author = "Ilja / fubits")
options(blogdown.ext = ".Rmd")
options(blogdown.widgetsID = TRUE)

as per Yihui: possible Speed improvements

(install.packages("processx"))
options(blogdown.generator.server = TRUE) # see serve_site() docs

jump to changes, when previewing

options(blogdown.hugo.server = c("-D", "-F", "--navigateToChanged"))

Formula

$A = \pi*r^{2}$

Data

(deprecated)

../../data/

elegant with here()

data_path <- here::here("data", "IRA_Tweets", "/")

Sourcing

\```{r setup}
knitr::read_chunk("example.R")
\```

add chunk marker in the sourced file example.R (## ---- chunk)

## ---- chunk
1 + 1

Play Sound after Task

BRRR::skrrrahh("flava")

Pictures

chunk / figure size options

```{r fig.width=7, out.width='100%'}

with italic formatting and Link

![*Screenshot of the GitLab Dashboard for the GitHub Importer on June 4th; [Source](https://monitor.gitlab.net/dashboard/db/github-importer?orgId=1&from=1528041600000&to=now){target="_blank"}*](/img/GitLab_JSON/gitlab_dashboard.jpg "alt-text")
Screenshot of the GitLab Dashboard for the GitHub Importer on June 4th; Source

Screenshot of the GitLab Dashboard for the GitHub Importer on June 4th; Source

Formatting and Alt-text

![*73 Topics, K auto-induced with t-SNE/PCA, modelled with the stm()-package*](/img/GitLab_JSON/gitlab_dom2.jpg "alt-text")
73 Topics, K auto-induced with t-SNE/PCA, modelled with the stm()-package

73 Topics, K auto-induced with t-SNE/PCA, modelled with the stm()-package

Custom Caption with class .caption

[![](/img/GIS_workflow/gppi_syria_1200px.jpg "Selected visuals from the Nowhere to Hide study on the use of Chemical Weapons in Syria.")](https://www.gppi.net/2019/02/17/the-logic-of-chemical-weapons-use-in-syria){target="_blank"}

<p><figcaption class="caption">Selected visuals from the "Nowhere to Hide" study on the use of Chemical Weapons in Syria. Read the [full report on GPPi's website](https://www.gppi.net/2019/02/17/the-logic-of-chemical-weapons-use-in-syria){target="_blank"}. Almost all maps are CC-licensed.</figcaption></p>

Selected visuals from the “Nowhere to Hide” study on the use of Chemical Weapons in Syria. Read the full report on GPPi’s website. Almost all maps are CC-licensed.

Emojis

emo::ji("smile")

As inline 'r emo::ji("smile")'

(full list: https://github.com/hadley/emo)

Undocumented

Skimr

# options(knitr.table.format = "html") OR
skimr::skim_to_wide(mtcars) %>% knitr::kable("html", 2)
## Warning: 'skimr::skim_to_wide' is deprecated.
## Use 'skim()' instead.
## See help("Deprecated")
skim_type skim_variable n_missing complete_rate numeric.mean numeric.sd numeric.p0 numeric.p25 numeric.p50 numeric.p75 numeric.p100 numeric.hist
numeric mpg 0 1 20.09 6.03 10.40 15.43 19.20 22.80 33.90 ▃▇▅▁▂
numeric cyl 0 1 6.19 1.79 4.00 4.00 6.00 8.00 8.00 ▆▁▃▁▇
numeric disp 0 1 230.72 123.94 71.10 120.83 196.30 326.00 472.00 ▇▃▃▃▂
numeric hp 0 1 146.69 68.56 52.00 96.50 123.00 180.00 335.00 ▇▇▆▃▁
numeric drat 0 1 3.60 0.53 2.76 3.08 3.70 3.92 4.93 ▇▃▇▅▁
numeric wt 0 1 3.22 0.98 1.51 2.58 3.33 3.61 5.42 ▃▃▇▁▂
numeric qsec 0 1 17.85 1.79 14.50 16.89 17.71 18.90 22.90 ▃▇▇▂▁
numeric vs 0 1 0.44 0.50 0.00 0.00 0.00 1.00 1.00 ▇▁▁▁▆
numeric am 0 1 0.41 0.50 0.00 0.00 0.00 1.00 1.00 ▇▁▁▁▆
numeric gear 0 1 3.69 0.74 3.00 3.00 4.00 4.00 5.00 ▇▁▆▁▂
numeric carb 0 1 2.81 1.62 1.00 2.00 2.00 4.00 8.00 ▇▂▅▁▁

Better Skimr

gapminder::gapminder %>% 
  skimr::skim_to_wide() %>%
  select(-top_counts, -(p0:p100)) %>% 
  knitr::kable("html", 1)

Tweets

Shortcode

{{ if not .Site.IsServer }} {{< tweet 981532034106576901 >}}

R Markdown / Chunk

Debugging

call Hugo directly on Win10

%APPDATA%\Hugo\hugo

measure rendering time

hugo --templateMetrics

OR

blogdown::hugo_cmd("--templateMetrics")