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 | |
| if [ $# = 0 ] | |
| then | |
| check_dir=. | |
| else | |
| check_dir=$1 | |
| fi | |
| rproj_files=$(ls -1 $check_dir/*.Rproj 2> /dev/null) |
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
| library(data.table) | |
| library(viridisLite) | |
| NN = 1e6 | |
| col = viridis(NN - 1L) | |
| ll = 1 | |
| points = data.table(x = numeric(NN), y = numeric(NN)) | |
| # one cumsum accumulates the rotational angle, the other cumsum | |
| # accumulates the accumulated angle | |
| points[ , theta := cumsum(cumsum(rep(runif(1L, 0, pi/2), .N)))] |
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
| library(data.table) | |
| library(colourvalues) | |
| library(RColorBrewer) | |
| # palette from: https://www.color-hex.com/color-palette/40131 | |
| # raw = c('#eeaf61', '#fb9062', '#ee5d6c', '#ce4993', '#6a0d83') | |
| # bump_col = function(col, n) do.call(rgb, as.list(pmax(pmin((col2rgb(col) + n)/256, 1), 0))) | |
| # dput(sapply(raw, function(col) c(bump_col(col, 16), bump_col(col, -16)))) | |
| sunset = c( | |
| "#FDBE71", "#DD9E51", | |
| "#FF9F72", "#EA8052", |
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
| library(data.table) | |
| # get paths to the relevant scripts into this vector | |
| files = list.files('~/gitlab', recursive = TRUE, full.names = TRUE, pattern = '\\.[rR]$') | |
| files = grep('\\.Rcheck|/tests/', f, value = TRUE, invert = TRUE) | |
| # examine an expression; if it's a call, the first element is the function, and | |
| # we continue to recursively check the other arguments for nested calls | |
| extract_calls = function(exp) { | |
| if (is.call(exp)) | |
| return(list(as.character(exp[[1L]]), lapply(exp[-1L], extract_calls))) |
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
| library(jsonlite) | |
| library(data.table) | |
| library(sf) | |
| library(geohashTools) | |
| library(colourvalues) | |
| # via https://www.google.com/maps/timeline > cog > Download a copy of your data; | |
| # mine from 5 years came out to 30Mb, roughly 21M lines | |
| loc = read_json('Location History/Location History.json') | |
| # initial flattening; activity is now a list column |
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
| ------ do_timings.sh ------ | |
| #!/bin/sh | |
| cd ~/github/geohashTools | |
| git checkout master && R CMD INSTALL . --preclean | |
| Rscript timing_script.R old | |
| git checkout move_to_c && R CMD INSTALL . --preclean | |
| Rscript timing_script.R new | |
| ------ timing_scrip.R ------ |
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
| # do persistence on integers-as-strings to sidestep 64-bit max | |
| pers = function(n) { | |
| sapply(strsplit(trimws(sprintf('%40.0f', n)), NULL), function(s) prod(as.integer(s))) | |
| } | |
| # pers0 = self, then persi = digits product applied i times | |
| DT = data.table(pers0 = 1:1e6, key = 'pers0') | |
| i = 0L | |
| while (TRUE) { |
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
| PKG = 'pkgdown' | |
| deps = tools::package_dependencies(PKG)[[1L]] | |
| sapply(deps, library, character.only = TRUE) | |
| library(PKG, character.only = TRUE) | |
| pkg_env = asNamespace(PKG) | |
| fun_re = sprintf('(?:%s:::?)?(?:%s|`[^`]+`)(?=\\()', | |
| .standard_regexps()$valid_package_name, | |
| "([[:alpha:]]|[.][._[:alpha:]])[._[:alnum:]]*") | |
| fun_tree = data.table::rbindlist(sapply(ls(pkg_env, all = TRUE), function(fun) { |
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
| parent_function,child_function,child_package | |
| [.tag,structure,base | |
| [.tag,NextMethod,base | |
| [.tag,class,base | |
| a,ifelse,base | |
| a,is.na,base | |
| a,paste0,base | |
| add_github_links,paste0,base | |
| add_github_links,gsub,base | |
| add_github_links,is.null,base |
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
| library(rgeos) | |
| library(magrittr) | |
| library(parallel) | |
| library(colourvalues) | |
| # upper-left coordinates in stretched space | |
| # (it turns out x coordinates are always multiples of 1/2, | |
| # y coordinates are always multiples of sqrt(3)/2) | |
| UL = cbind(rep(c(-7+6*(0:2), -4+6*(0:1)), length.out = 23L), | |
| rep(5:-3, rep(3:2, length.out = 9L))) |