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
| require(tmap) | |
| require(dplyr) | |
| require(stars) | |
| require(shiny) | |
| server = shinyServer(function(input, output, session) { | |
| tmap_mode("view") | |
| output$map = renderTmap({ |
This file has been truncated, but you can view the full file.
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <style>body{background-color:white;}</style> | |
| <script src="data:application/javascript;base64,KGZ1bmN0aW9uKCkgewogIC8vIElmIHdpbmRvdy5IVE1MV2lkZ2V0cyBpcyBhbHJlYWR5IGRlZmluZWQsIHRoZW4gdXNlIGl0OyBvdGhlcndpc2UgY3JlYXRlIGEKICAvLyBuZXcgb2JqZWN0LiBUaGlzIGFsbG93cyBwcmVjZWRpbmcgY29kZSB0byBzZXQgb3B0aW9ucyB0aGF0IGFmZmVjdCB0aGUKICAvLyBpbml0aWFsaXphdGlvbiBwcm9jZXNzICh0aG91Z2ggbm9uZSBjdXJyZW50bHkgZXhpc3QpLgogIHdpbmRvdy5IVE1MV2lkZ2V0cyA9IHdpbmRvdy5IVE1MV2lkZ2V0cyB8fCB7fTsKCiAgLy8gU2VlIGlmIHdlJ3JlIHJ1bm5pbmcgaW4gYSB2aWV3ZXIgcGFuZS4gSWYgbm90LCB3ZSdyZSBpbiBhIHdlYiBicm93c2VyLgogIHZhciB2aWV3ZXJNb2RlID0gd2luZG93LkhUTUxXaWRnZXRzLnZpZXdlck1vZGUgPQogICAgICAvXGJ2aWV3ZXJfcGFuZT0xXGIvLnRlc3Qod2luZG93LmxvY2F0aW9uKTsKCiAgLy8gU2VlIGlmIHdlJ3JlIHJ1bm5pbmcgaW4gU2hpbnkgbW9kZS4gSWYgbm90LCBpdCdzIGEgc3RhdGljIGRvY3VtZW50LgogIC8vIE5vdGUgdGhhdCBzdGF0aWMgd2lkZ2V0cyBjYW4gYXBwZWFyIGluIGJvdGggU2hpbnkgYW5kIHN0YXRpYyBtb2RlcywgYnV0CiAgLy8gb2J2aW91c2x5LCBTaGlueSB3aWRnZXRzIGNhbiBvbmx5IGFwcGVhci |
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
| n | lat | lon | |
|---|---|---|---|
| 342 | 14.765625 | 45.703125 | |
| 307 | 21.796875 | 94.921875 | |
| 265 | 37.265625 | 127.265625 | |
| 172 | 31.640625 | 35.859375 | |
| 156 | 31.640625 | 34.453125 | |
| 151 | 35.859375 | 37.265625 | |
| 141 | 48.515625 | 38.671875 | |
| 138 | 35.859375 | 35.859375 | |
| 138 | 18.984375 | -99.140625 |
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
| # function for parsing strings where quotes are not escaped but nested inside triple-quotes | |
| escape_triple_quoted = function(j){ | |
| j_split = strsplit(j, '"{3}')[[1]] | |
| f = seq_along(j_split) %% 2 == 0 # filter | |
| j_split[f] = gsub('"', '\\\\"', j_split[f]) | |
| paste(j_split, collapse = '"') | |
| } | |
| # Usage |
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
| # identify and fill missing data points in timeseries data with regular-periodicity | |
| require(padr) | |
| #> Loading required package: padr | |
| df <- data.frame(date = as.Date('2016-04-01') + 3*c(0,1,3,5,6), val = sample(5)) |> | |
| print() | |
| #> date val | |
| #> 1 2016-04-01 3 | |
| #> 2 2016-04-04 1 |
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
| require(wayback) | |
| url = 'https://bbc.com' | |
| wb = wayback::archive_available(url) | |
| wb$closet_url | |
| wb_mems = wayback::get_mementos(u) | |
| wb_mems$link |
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
| # String in text (vectorised) | |
| # A Python-style String in Text operator that ignores case. Either x or pattern must be a single value. Returns a logical value or vector. | |
| {\(pattern, x) stringi::stri_detect_regex(x, pattern, case_insensitive = TRUE)} -> `%IN%` | |
| # usage | |
| 'dog' %IN% 'the nice dog said hello' | |
| #> [1] 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
| # Function to report all explicit R dependencies in current directory (recursive) | |
| # This ignores dependencies of dependencies, but output can be piped to tools::package_dependencies() | |
| report_dependencies = function(path = './', print = FALSE, simple = TRUE){ | |
| files = list.files(path = path, pattern = '.R$', recursive = TRUE, full.names = TRUE) | |
| scripts = lapply(files, readLines, warn = FALSE) |> unlist() |> paste(collapse = '\n') | |
| loaded = scripts |> stringr::str_extract_all('(?<=(library|require)\\()[a-zA-Z0-9_.]+') |> unlist() |> | |
| stringr::str_remove_all('["\']') |> stringr::str_remove(',.*') |> unique() |> sort() | |
| invoked = scripts |> stringr::str_extract_all('[a-zA-Z0-9_.]+(?=::)') |> unlist() |> unique() |> sort() |
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
| # replace strings with mode case | |
| require(dplyr) | |
| case_lump = function(x){ | |
| x1 = tibble::enframe(x, name=NULL) |> mutate(id = 1:n(), lower = tolower(value)) | |
| x1 |> count(value, lower, sort = TRUE) |> | |
| group_by(lower) |> slice(1) |> ungroup() |> | |
| rename(mode = value) |> | |
| left_join(x1, by = 'lower') |> |
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
| { | |
| "id": "0igifmdu25", | |
| "product_class": "", | |
| "process": "", | |
| "source_type": "", | |
| "product_category": "BIOGRAPHY", | |
| "regions": [], | |
| "primary_country_tag": "ZMB", | |
| "topic_tags": [], | |
| "country_tags_full": ["Zambia"], |