Skip to content

Instantly share code, notes, and snippets.

View jdblischak's full-sized avatar

John Blischak jdblischak

View GitHub Profile
`for` <- function(it, seq, expr) {
if(!identical(substitute(it), quote(.))) {
tryCatch(
eval.parent(substitute(base::`for`(it, seq, expr))),
error = function(e) {stop(c("In `for`: ", e$message), call. = FALSE)})
return(invisible())
}
l <- length(seq[[1]])
nms1 <- names(seq)
nms2 <- paste0("*", names(seq), "*")

Q1. Are all the latest release versions of tidyverse and tidymodels packages already using cpp11?

All tidyverse packages that used Rcpp have been converted except for readxl and lubridate. We plan to finish converting the remainder of the packages in the next 6 months.

Q2. C++20 brings a lot of exciting features to the language, do you plan to also add a {cpp20} package too?

I agree! It is possible, but it would not be for at least 5 to 7 years from now, if ever. Compiler support and availablity often lags the language specifications significantly. However you can definitely use C++20 features with cpp11 in your package today if you like!

Q3. So writable:: is like not using const& in Rcpp?

options(typed.typed = TRUE)
`%typed%` <- function(e1, e2) {
if(getOption("typed.typed")) {
assert_call <- substitute(e1)
assert_call[[1]] <- quote(assertthat::assert_that)
eval.parent(assert_call)
}
e2
}
@thoolihan
thoolihan / clip.R
Last active October 10, 2020 14:33
data <- -10:10
lims <- range(data)
x <- sample(data, 50, replace = TRUE)
par(mfrow=c(1, 5))
plot(x, ylim=lims, main="initial data")
# only positive
plot(pmax(x, 0), ylim=lims, main="clip bottom")
@mfansler
mfansler / list_export_to_yaml.awk
Last active November 28, 2024 16:41
Convert `conda list` output to YAML
#!/usr/bin/env awk -f
#' Author: Mervin Fansler
#' GitHub: @mfansler
#' License: MIT
#'
#' Basic usage
#' $ conda list --export | awk -f list_export_to_yaml.awk
#'
#' Omitting builds with 'no_builds'
#' $ conda list --export | awk -v no_builds=1 -f list_export_to_yaml.awk
create_lazy_bindings <- function(x, ...){
environment()
}
# object df is in the environment but has not been evaluated
e <- create_lazy_bindings(y)
ls(e)
#> [1] "x"
# thus this won't work
@dmi3kno
dmi3kno / match_to_formals.R
Last active June 13, 2020 17:02
Example of formals-aware decorator
is.unset<-function(x)
x==as.list(alist(a=))[[1]]
is.nameempty <- function(x){
nx <- names(x)
if(is.null(nx))
return(rep(TRUE, length(x)))
is.na(nx) | nx==""
}
@akhanf
akhanf / snakemake_remotebatch
Created April 21, 2020 13:06
batch submission script
#!/bin/bash
hours=6
mem=128000
gpus=1
cpus=32
if [ "$#" -lt 2 ]
then
echo "Usage $0 RULE_NAME NUM_BATCHES <optional snakemake args>"
@ha0ye
ha0ye / gist:197de5797df1d4e2b14a8bff4fb99c95
Created March 28, 2020 01:15
pairwise overlap calculations
calc3 <- function(sets)
{
sets <- check_sets(sets)
set_lengths <- vapply(sets, length, 0)
set_order <- order(set_lengths)
sets <- sets[set_order]
set_lengths <- set_lengths[set_order]
n_sets <- length(sets)
set_names <- names(sets)
@gaborcsardi
gaborcsardi / Pkgdown deploy from Travis.md
Last active November 17, 2021 13:41
Walkthrough: deploy a pkgdown site from Travis

Run usethis::use_pkgdown_travis()

usethis::use_pkgdown_travis()
✔ Setting active project to '/Users/gaborcsardi/works/ps'Adding 'docs/' to '.gitignore'Set up deploy keys by running `travis::use_travis_deploy()`Insert the following code in '.travis.yml'
  before_cache: Rscript -e 'remotes::install_cran("pkgdown")'