Skip to content

Instantly share code, notes, and snippets.

View cderv's full-sized avatar

Christophe Dervieux cderv

View GitHub Profile
@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
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 / 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
@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 / 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 / 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 / How-to.md
Created December 10, 2020 14:12
Deploy Bookdown to RStudio Connect programatically

How to deploy to Rstudio Connect : Push mode

Theory

  • Create a manifest using rsconnect
  • Use API to create content on RSC -> GUID
  • Create a tar.gz bunlde with the manifest
  • USe API to push the bundle

Creating a Manifest

@cderv
cderv / Makefile
Last active February 9, 2021 10:15
TOC in GFM output by Pandoc
all: test-gfm2.md test-gfm.md
test-gfm2.md: test.md
pandoc -f markdown+gfm_auto_identifiers -t gfm -s --table-of-contents -o $@ $<
test-gfm.md: test.md
pandoc -f markdown -t gfm -s --table-of-contents -o $@ $<
@cderv
cderv / import.lua
Last active April 9, 2021 08:50
import a script in a Pandoc lua filter
-- MIT LICENCE - 2021 Christophe Dervieux
-- Only works with Pandoc 2.1.2+ because of PANDOC_SCRIPT_FILE availability
function import(script)
local PATH_SEP = package.config:sub(1,1)
local path = PANDOC_SCRIPT_FILE:match("(.*"..PATH_SEP..")")
dofile(path .. script)
end
import("utils.lua")