View update.R
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
# Example 1: running at top level. This works. | |
model_str1 <- "speed~dist" | |
model1 <- lm(formula=model_str1, data=cars) | |
stats::update(model1, y = TRUE) | |
#> | |
#> Call: | |
#> lm(formula = model_str1, data = cars, y = TRUE) | |
#> | |
#> Coefficients: | |
#> (Intercept) dist |
View modify_expr.R
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
# This function recurses into `expr`, looking for `search_expr`. If it finds | |
# it, it will return `replace_expr`. Notably, `replace_expr` can contain rlang | |
# operators like `!!`, and perform rlang substitution on them. | |
modify_expr <- function( | |
expr, | |
search_expr, | |
replace_expr | |
) { | |
if (typeof(expr) != "language") { | |
stop("modify_expr only works on language objects (AKA quoted expressions)!") |
View app.R
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
# Test app for https://github.com/rstudio/shiny/pull/3666 | |
# pkgload::load_all() | |
library(promises) | |
library(httpuv) | |
library(htmltools) | |
library(shiny) | |
library(later) | |
options(shiny.minified = FALSE) |
View grow_vector.R
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
# The code below demonstrates that in R, growing a vector in a loop can be fast, | |
# as long as there is only reference to the object. When there's only one | |
# reference to the vector, R grows it in place (in most cases). However, if | |
# there are other references to the object, R must make a copy the object | |
# instead of growing it in place, leading to slower performance. | |
# ========================================================================= | |
# Timing tests | |
# ========================================================================= |
View index.html
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
This is a test, v2! |
View web_repl.R
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
# Web REPL/console | |
# Note: 127.0.0.1 allows connections only from localhost. To listen on external | |
# ports, use 0.0.0.0. | |
web_repl <- function(host = "127.0.0.1", port = 8080) { | |
library(httpuv) | |
app <- list( | |
call = function(req) { |
View pluck_recursive.R
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
# @drob's version from https://twitter.com/drob/status/1501747414780239879 | |
pluck_recursive <- function(lst, name) { | |
if (is.list(lst)) { | |
if (!is.null(lst[[name]])) { | |
return(lst[[name]]) | |
} | |
return(unname(unlist(purrr::map(lst, pluck_recursive, name)))) | |
} | |
} |
View mtime.R
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) | |
get_mtime <- cfunction( | |
signature(filename = "character"), | |
includes = " | |
#include <time.h> | |
#include <sys/stat.h>", | |
body = ' | |
const char* path = CHAR(asChar(filename)); | |
struct stat attr; | |
stat(path, &attr); |
View contextvars.py
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
# Demonstration of using ContextVars instead of global variables. | |
# Set to True for global mode, False for ContextVar mode | |
global_mode = False | |
# With a global variable, the result is: 1 2 3 3 3 3 3 3 3 | |
# With a ContextVar, the result is: 1 2 3 1 2 3 1 2 3 | |
import asyncio | |
import contextvars |
View later_test.R
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
# This code uses later's C API to schedule callbacks as quickly as possible, and | |
# it tests if the callbacks execute in the same order that they are scheduled. | |
# In Docker on Mac, they sometimes do not. | |
docker run --rm -ti rocker/shiny /bin/bash | |
R | |
install.packages(c('cpp11', 'later', 'brio', 'callr', 'cli', 'decor', 'desc', | |
'tibble', 'vctrs')) | |
library(cpp11) |
NewerOlder