-
Dropping attributes
matrix[, 1, drop=FALSE]
-
Autocompletion for thee but not for me
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| `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?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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=="" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| hours=6 | |
| mem=128000 | |
| gpus=1 | |
| cpus=32 | |
| if [ "$#" -lt 2 ] | |
| then | |
| echo "Usage $0 RULE_NAME NUM_BATCHES <optional snakemake args>" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |