Skip to content

Instantly share code, notes, and snippets.

View cderv's full-sized avatar

Christophe Dervieux cderv

View GitHub Profile
@cderv
cderv / example.R
Last active October 5, 2017 19:24
TidyEvalution with testthat
library(testthat)
library(lubridate)
base <- as.POSIXct("2009-08-03 12:01:59.23", tz = "UTC")
expect_floor_equal <- function(unit, time) {
unit <- rlang::enquo(unit)
time <- rlang::enquo(time)
as_time <- function(x) as.POSIXct(x, tz = "UTC")
rlang::expr(expect_equal(floor_date(base, rlang::UQE(unit)), as_time(rlang::UQE(time))))
@cderv
cderv / nested_list_data.R
Last active June 10, 2020 20:59
data for nested list example
#' From a stackoverflow question : https://stackoverflow.com/questions/46128164/extract-data-from-a-nested-list-with-loops#46128164
nested_list_ex <- structure(list(scheduleList = structure(list(
schedule = structure(list(
score = structure(list(
class = structure(list(name = list("011c"), people = list("2"), teacher = structure(list(name = list("A")), .Names = "name", id = "D29")), .Names = c("name", "people", "teacher"), id = "011c", status = "-2"),
class = structure(list(name = list("013"), people = list("0"), teacher = structure(list(name = list("B")), .Names = "name", id = "D14")), .Names = c("name", "people", "teacher"), id = "602d", status = "-4"),
class = structure(list(name = list("603"), people = list("6"), teacher = structure(list(name = list("C")), .Names = "name", id = "D31")), .Names = c("name", "people", "teacher"), id = "603", status = "-4")),
.Names = c("class", "class", "class"), id = "1"),
score = structure(list(
class = structure(list(name = list
@cderv
cderv / about_download_methods.md
Last active January 12, 2024 02:43
download file methods in R

download.file methods in R

Working on a PR for remotes package (this PR), I looked into how download.file methods evolved with R version, trying to understand how it works depending on the system or the url type.

Here is my understanding.

History of download.file

from R news

R 3.3.0

@cderv
cderv / Config_proxy.R
Last active October 22, 2020 17:07
Proxy Configuration
# Read a pasword using a prompt
read_Password <- function(prompt) {
if (requireNamespace("rstudioapi")) {
pwd <- rstudioapi::askForPassword(prompt)
} else if (exists(".rs.askForPassword")) {
pwd <- .rs.askForPassword(prompt)
} else {
pwd <- readline(prompt)
}
return (pwd)
@cderv
cderv / Theme_Markdown.css
Created February 13, 2016 15:02
Template for custome documenth
h1{
color: white;
padding: 10px;
background-color: #3399ff
}
ul {
list-style-type: square;
}
@cderv
cderv / RStudio_snippet.md
Last active October 22, 2020 17:07
my custom snippet for RStudio

To insert YAML header for Rnotebook

snippet yaml_notebook_html
	#' ---
	#' title: "${1:title}"
	#' author: "${2:author}"
	#' knit: (function(inputFile, encoding) { rmarkdown::render(inputFile, encoding = encoding, output_file = sprintf("%s_%s.html", format(Sys.Date(), "%y%m%d"), basename(tools::file_path_sans_ext(inputFile))))})
	`r paste("#' date: '\u0060r paste(\u0022", format(Sys.time(), "%d/%m/%Y")," - Dernière MAJ:\u0022, format(Sys.time(), \u0022%d/%m/%Y\u0022))\u0060'", sep = "")`
	#' output : 
	#' html_document:
@cderv
cderv / README.md
Created September 23, 2015 17:15 — forked from romainfrancois/README.md
getting github issues for a given repo

Simple R script that grabs the opened issues from a github repo :

$ github_issues hadley/dplyr
   number           user                                                         title                labels
1      98         hadley                                   Setup databases with travis           enhancement
2      97         hadley                                               Unique operator           enhancement
3      96         hadley                           Implement right join and outer join           enhancement
4      95 romainfrancois                                             Hybrid evaluation enhancement, internal
5      94         hadley                 Make sure all vignettes work from R CMD check                   bug