Skip to content

Instantly share code, notes, and snippets.

View cderv's full-sized avatar

Christophe Dervieux cderv

View GitHub Profile
@cderv
cderv / R_in_lua.Rmd
Created November 30, 2020 16:02
R in lua
---
title: "Use R in a lua filter"
output:
html_document:
pandoc_args: !expr rmarkdown::pandoc_lua_filter_args("my.lua")
---
This document will have uppercase header using R function `toupper()`
```{cat, engine.opts = list(file = "my.lua")}
@cderv
cderv / apply-labels.R
Created November 24, 2020 09:48
Tidyverse labels-ish
library(magrittr)
library(usethis)
# We want to keep question and not rename it to reprex so
# 1. Add question label with color and description
# 2. Remove renaming of question to reprex
labels <- c(tidy_labels(), "question")
rename <- tidy_labels_rename() %>% {.[names(.) != "question"]}
colors <- c(tidy_label_colours(), "FBCA04")
description <- c(tidy_label_descriptions(), "questions not answered anywhere else")
@cderv
cderv / test-usermode.md
Created November 12, 2020 17:35
Test USERMODE with TeX Live

Commands to test

mkdir ~/.MyTeX
TEXMFHOME=~/.MyTeX
echo $TEXMFHOME
ls $TEXMFHOME
TEXMFHOME=$TEXMFHOME tlmgr init-usertree
ls $TEXMFHOME
TEXMFHOME=$TEXMFHOME tlmgr --usermode install caption
@cderv
cderv / failure.txt
Created October 19, 2020 09:16
Error while building a bookdown book
==> rmarkdown::render_site(output_format = 'bookdown::gitbook', encoding = 'UTF-8')
|......................................................................| 100%
inline R code fragments
processing file: index.Rmd
output file: index.knit.md
get_pandoc_metadata <- function(file, to = "html") {
template <- tempfile(fileext = ".json")
json_out <- tempfile(fileext = ".json")
xfun::write_utf8("$meta-json$", template)
template_arg <- sprintf("--template=%s", template)
rmarkdown::pandoc_convert(file, from = "markdown", to = to,
options = c(template_arg),
output = json_out)
jsonlite::fromJSON(json_out)
}
@cderv
cderv / 00-New setup.md
Last active April 22, 2025 18:37
New computer setup
# installed by winget
winget install PowerShell-Preview
winget install git
git config --global user.name "Christophe Dervieux"
git config --global user.email christophe.dervieux@gmail.com
winget install rstudio
winget install vscode
winget install -e R
winget install Github.GithubDesktop
@cderv
cderv / get_raw_chunks.R
Last active July 21, 2020 07:30 — forked from nischalshrestha/get_raw_chunks.R
Raw knitr chunks (inside hook context)
# test file
sample_chunk <- "
```{r hello, testing=as.logical(1), another=1 + 1}
1 + 1
```"
file = "sample.Rmd"
writeLines(sample_chunk, con = file)
foo_hook = function(before, options, envir) {
# only run after the chunk
if (before) return()
@cderv
cderv / manual-test.Rmd
Last active November 23, 2019 17:49
Test for knitr issue on include_graphics (https://github.com/yihui/knitr/pull/1776)
# one graphic
```{r, fig.cap = "This is a caption for unique figure"}
knitr::include_graphics("test-1.png")
```
# Three graphics in the same chunk
Using three times `include_graphics`