Skip to content

Instantly share code, notes, and snippets.

View cderv's full-sized avatar

Christophe Dervieux cderv

View GitHub Profile
@cderv
cderv / knitr_child_ex1.Rmd
Last active January 27, 2019 16:03
Examples for Rmarkdown cookbook
---
title: "Programmatically create a document"
date: "`r Sys.Date()`"
output:
pagedown::html_paged:
toc: true
# change to true for a self-contained document, but it'll be a litte slower for Pandoc to render
self_contained: false
---
@cderv
cderv / getDOM.R
Last active March 2, 2019 16:05
CRRRI STUFF
# Based on issue https://github.com/RLesur/crrri/issues/30
# from Rlesur/crrri@feature/build-on-cdp-session
# tested with 59747341
devtools::load_all()
# launch
work_dir <- chr_new_data_dir()
chrome <- chr_launch(work_dir = work_dir, headless = TRUE)
@cderv
cderv / notes.md
Created March 3, 2019 12:01
setup R build tools

To compile R Source on windows

  • BINPREF must be set to C:/Rtools/mingw_$(WIN)/bin/ (/ are important)
  • Rtools must be on the path: C:\\Rtools\\bin\\; (/ less important)

This will make installation ok no matter the 📦 (like remotes)

What to know about RStudio

install.packages in rstudio is not directly utils::install.packages(). There is some things set after some verification. Like setting BINPREF.

@cderv
cderv / update_git_remote.R
Created April 5, 2019 16:21
update git remote to new url
# Copyright (C) 2018 C. Dervieux
# Licence MIT - https://spdx.org/licenses/MIT.html
#' Update git remote url from R
#'
#' If git remote server is migrated and url is changed, this function allows to easily update
#' the url of local git repo to the new git remote url.
#'
#' This function need `git2r`, `urltools` and `glue` to work.
#'
@cderv
cderv / 2column_html_format.Rmd
Created April 11, 2019 13:44
Two column layout in rmarkdown
---
title: "test"
output:
html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
@cderv
cderv / swagger_viewer.R
Last active October 22, 2020 17:02
Launch swagger json in RStudio Viewer
swagger_viewer <- function(json_doc) {
folder_path <- fs::path_temp("swagger")
if (!fs::dir_exists(folder_path)) {
fs::dir_copy(swagger::swagger_path(), folder_path)
}
fs::file_copy(json_doc, folder_path)
index <- xfun::read_utf8(fs::path_temp("swagger", "index.html"))
index_new <- gsub("http://petstore.swagger.io/v2/swagger.json", json_doc, index)
xfun::write_utf8(index_new, fs::path_temp("swagger", "index.html"))
rstudioapi::viewer(fs::path_temp("swagger", "index.html"))
@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`
@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()