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
| { | |
| "breadcrumbs.enabled": false, | |
| "diffEditor.codeLens": true, | |
| "editor.acceptSuggestionOnEnter": "off", | |
| "editor.bracketPairColorization.enabled": false, | |
| "editor.cursorBlinking": "phase", | |
| "editor.cursorStyle": "line", |
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
| # Apr 2024: stripped out several packages from the list that were loaded as dependencies anyway | |
| pkgs <- c( | |
| "usethis", | |
| "tidyterra", | |
| "devtools", | |
| "tmap", | |
| "janitor", | |
| "afcolours", | |
| "arrow", | |
| "assertthat", |
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
| [ | |
| { | |
| "key": "ctrl+d", | |
| "command": "editor.action.deleteLines", | |
| "when": "textInputFocus && !editorReadonly" | |
| }, | |
| { | |
| "key": "ctrl+shift+k", | |
| "command": "-editor.action.deleteLines", | |
| "when": "textInputFocus && !editorReadonly" |
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( | |
| usethis.full_name = "Fran Barton", | |
| usethis.protocol = "ssh", | |
| usethis.description = list( | |
| `Authors@R` = 'person( | |
| "Fran", "Barton", | |
| email = "[email protected]", | |
| role = c("aut", "cre"), | |
| comment = c(ORCID = "0000-0002-5650-1176") | |
| )', |
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
| # originally written at | |
| # https://community.rstudio.com/t/unlist-columns-with-lists-of-different-length/ | |
| # with grateful acknowledgement of those who worked it out before me :-) | |
| ## improved (well, single pipe) version, to summarise values in a df into a summary table | |
| rectangularise <- function(df) { | |
| df %>% | |
| purrr::map(unique) %>% | |
| purrr::map(sort) %>% | |
| purrr::map(~ `length<-`(., max(lengths(map(df, ~ unique(.)))))) %>% |
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
| # https://gist.github.com/francisbarton/a5907ec17154a59d5c9058d64b3012f5 | |
| # I use this pattern regularly in chatty packages | |
| snippet inf | |
| usethis::ui_info( | |
| stringr::str_glue("") | |
| ) | |
| # set up a testthat block | |
| snippet testt |
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(conflicts.policy = list(warn.conflicts = FALSE)) | |
| library(dplyr) # A Grammar of Data Manipulation | |
| summarise_groups <- function(df, grouping_var, column_name){ | |
| df %>% | |
| group_by({{grouping_var}}) %>% | |
| summarise("{{column_name}}_mean" := mean({{column_name}}, na.rm = TRUE)) | |
| } | |
| dplyr::storms %>% |
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
| # Get postcode metadata from postcodes.io | |
| get_postcode_metadata <- function(postcodes) { | |
| endpoint <- "https://api.postcodes.io/postcodes" | |
| body <- list(postcodes = postcodes) | |
| out <- httr::POST(url = endpoint, body = body, encode = "json") | |
| # thanks to https://github.com/ropensci/PostcodesioR/blob/master/R/postcode_lookup.R for setting a good example with httr | |
| httr::warn_for_status(out) |
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
| # Use the doogal.co.uk API to get data about a postcode | |
| # Doesn't accept a vector of codes all at once, so use with purrr::map_dfr() | |
| # along a vector to combine results into a data frame | |
| get_doogal_data <- function(postcode) { | |
| data_names <- c( | |
| "postcode", | |
| "latitude", | |
| "longitude", |
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
| ``` r | |
| library(dplyr, warn.conflicts = FALSE) | |
| library(purrr) | |
| library(rlang, warn.conflicts = FALSE) | |
| library(stringr) | |
| filenames <- c("coronavirus_cases_202007061134.csv", "coronavirus_cases_202007071134.csv", "coronavirus_cases_202007081134.csv") | |
| cases <- c(1000, 1500, 2000) | |
| # couple of functions |