This file contains 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
## Serialization Does Not Trigger Promises | |
fx <- ff(stop('boom')) | |
fxa <- ff(stop('boom')) | |
fy <- ff(stop('boom boom')) | |
identical(serialize(fx, NULL), serialize(fxa, NULL)) | |
## [1] TRUE | |
identical(serialize(fx, NULL), serialize(fy, NULL)) | |
## [1] FALSE |
This file contains 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
library(inline) | |
frow <- cfunction(sig=c(x='list'), body=' | |
R_xlen_t J = XLENGTH(x); | |
R_xlen_t n = XLENGTH(VECTOR_ELT(x, 0)); | |
SEXP out = PROTECT(allocVector(INTSXP, n)); | |
int *outp = INTEGER(out); | |
for (int j=0; j<J; j++) { | |
int *col = INTEGER(VECTOR_ELT(x, j)); | |
for (int i=0; i<n; i++) { | |
if(j) {outp[i] += col[i];} else {outp[i] = col[i];} |
This file contains 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
mk_name <- function(name=NULL) { | |
v <- as.character(packageVersion('rayrender')) | |
dir <- file.path('~', 'Downloads', 'rr-tests') | |
if(is.null(name)) { | |
name <- sprintf( 'a_%s.png', format(Sys.time(), "%Y-%m-%d_%H%M%S")) | |
} else { | |
name <- sprintf('%s.png', name) | |
} | |
file.path(dir, v, name) | |
} |
This file contains 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
## GPL-2 | |
## Tweet 1 | |
## From https://github.com/djnavarro/ohno | |
add_with <- function(z) function(x, y) x + y + z | |
add_with(10)(1, 2) # works | |
butcher <- function(x, y, f) { | |
env <- new.env() # create a new environment | |
environment(f) <- env |
This file contains 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
# Compute Device Size To Fully Fill With Plot | |
# | |
# This is not tested extensively and I know very little about messing with | |
# grid. | |
# | |
# GPL-2 | |
# | |
# @param gtable e.g. as produced by `ggplotGrob(ggplot() ...)` | |
# @param din device dimension in inches, ideally use defaults to avoid | |
# calculation issues with npc units. |
This file contains 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
# PNG to HTML | |
Code adapted from [@gdagstn](https://gist.github.com/gdagstn/1917e0e6f7dc91a8dde7cb789326c3bb). | |
```{r, echo=FALSE, comment="", results="asis"} | |
old.hooks <- fansi::set_knit_hooks(knitr::knit_hooks) | |
``` | |
```{r echo=FALSE} | |
library(crayon) |
This file contains 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
## Tests based on https://mailund.dk/posts/scoping-rules-and-nse/ | |
# rm(list=ls()) | |
if(length(ls())) message("you have variables defined in the environment") | |
library(wrapr) | |
lm_prop2a <- function(x, y, d, prop, eval) { | |
let(c(x = x, y = y, prop = prop, d=d), | |
summary(lm(y ~ x, data = d))$prop, | |
eval = eval, envir=parent.frame()) | |
} |
This file contains 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
faster_bilinear <- function (Z, x0, y0){ | |
i = floor(x0) | |
j = floor(y0) | |
XT = (x0 - i) | |
YT = (y0 - j) | |
result = (1 - YT) * (1 - XT) * Z[i, j] | |
nx = nrow(Z) | |
ny = ncol(Z) | |
if(i + 1 <= nx){ | |
result = result + (1-YT) * XT * Z[i + 1, j] |
This file contains 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
# started with `foghorn`, but that comes with dependencies and | |
# slows down R startup. `browseURL` just barely slows startup, | |
# even if actual page is slow to load. | |
check_cran_old <- function(email) { | |
utils::browseURL( | |
sprintf( | |
"https://cran.r-project.org/web/checks/check_results_%s.html", | |
gsub("[^A-Za-z0-9_:.-]", "_", sub("@", "_at_", email)) | |
) ) } |
This file contains 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
── 1. Failure: col_substr keeps color (@test-operations.R#31) ───────────────── | |
col_substr("\033[31mred\033[39m", 1, 1) not equal to "\033[31mr\033[39m". | |
1/1 mismatches | |
x[1]: "\033[31mr\033[0m" | |
y[1]: "\033[31mr\033[39m" | |
── 2. Failure: col_substr keeps color (@test-operations.R#33) ───────────────── | |
col_substr("foo\033[31mred\033[39m", 4, 4) not equal to "\033[31mr\033[39m". | |
1/1 mismatches | |
x[1]: "\033[31mr\033[0m" |
NewerOlder