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

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")
## <U+0001F604>

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)
type variable missing complete n mean sd p0 p25 p50 p75 p100 hist
numeric am 0 32 32 0.41 0.5 0 0 0 1 1 ▇▁▁▁▁▁▁▆
numeric carb 0 32 32 2.81 1.62 1 2 2 4 8 ▆▇▂▇▁▁▁▁
numeric cyl 0 32 32 6.19 1.79 4 4 6 8 8 ▆▁▁▃▁▁▁▇
numeric disp 0 32 32 230.72 123.94 71.1 120.83 196.3 326 472 ▇▆▁▂▅▃▁▂
numeric drat 0 32 32 3.6 0.53 2.76 3.08 3.7 3.92 4.93 ▃▇▁▅▇▂▁▁
numeric gear 0 32 32 3.69 0.74 3 3 4 4 5 ▇▁▁▆▁▁▁▂
numeric hp 0 32 32 146.69 68.56 52 96.5 123 180 335 ▃▇▃▅▂▃▁▁
numeric mpg 0 32 32 20.09 6.03 10.4 15.43 19.2 22.8 33.9 ▃▇▇▇▃▂▂▂
numeric qsec 0 32 32 17.85 1.79 14.5 16.89 17.71 18.9 22.9 ▃▂▇▆▃▃▁▁
numeric vs 0 32 32 0.44 0.5 0 0 0 1 1 ▇▁▁▁▁▁▁▆
numeric wt 0 32 32 3.22 0.98 1.51 2.58 3.33 3.61 5.42 ▃▃▃▇▆▁▁▂

Better Skimr

gapminder::gapminder %>% 
  skimr::skim_to_wide() %>%
  select(-top_counts, -(p0:p100)) %>% 
  knitr::kable("html", 1)
type variable missing complete n n_unique ordered mean sd hist
factor continent 0 1704 1704 5 FALSE NA NA NA
factor country 0 1704 1704 142 FALSE NA NA NA
integer pop 0 1704 1704 NA NA 3e+07 1.1e+08 ▇▁▁▁▁▁▁▁
integer year 0 1704 1704 NA NA 1979.5 17.27 ▇▃▇▃▃▇▃▇
numeric gdpPercap 0 1704 1704 NA NA 7215.33 9857.45 ▇▁▁▁▁▁▁▁
numeric lifeExp 0 1704 1704 NA NA 59.47 12.92 ▁▂▅▅▅▅▇▃

Tweets

Shortcode

{{< tweet 981532034106576901 >}}

R Markdown / Chunk

# {r echo=FALSE}
blogdown::shortcode('tweet', '852205086956818432')

Own reply-only Tweet shortcode

Cf. https://www.mgasch.com/post/shortcodes/

# {r echo=FALSE}
blogdown::shortcode('tweet-noreply', '1096850367609032705')

Debugging

call Hugo directly on Win10

%APPDATA%\Hugo\hugo

measure rendering time

hugo --templateMetrics

OR

blogdown::hugo_cmd("--templateMetrics")