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(dplyr) | |
# Which package to check | |
trias_namespace <- asNamespace("trias") | |
# Character vector of all functions and their arguments, print method of base ls with str() on every object | |
trias_fns_args <- capture.output(utils::lsf.str(trias_namespace)) | |
# Extract the functions |
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
round_coordinates <- function(wkt_string, digits = 4) { | |
wkt_object_type <- wkt_string %>% | |
stringr::str_extract(".*?(?=\\()") | |
x_coord <- wkt_string %>% | |
stringr::str_extract("(?<=POINT\\()[0-9]+\\.[0-9]+") %>% | |
as.numeric() | |
y_coord <- wkt_string %>% | |
stringr::str_extract("[0-9]+\\.[0-9]+(?=\\))") %>% |
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(magrittr) | |
exported_functions <- | |
readr::read_lines("NAMESPACE") %>% | |
stringr::str_extract("(?<=export\\().+(?=\\))") %>% | |
.[!is.na(.)] | |
unit_tests <- | |
list.files("tests/testthat/") %>% | |
stringr::str_extract("(?<=test-).+(?=\\.R)") %>% | |
.[!is.na(.)] |
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
format(Sys.time(), "%Y_%m_%d-%H_%M") |
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
str_replace_na <- function(string, replacement = ""){ | |
string[is.na(string)] <- replacement | |
return(string) | |
} | |
c("a", NA, "c") |> str_replace_na(replacement = "") |> paste0(collapse = " ") | |
#> [1] "a c" |
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
my_good_function <- function(seed = 789) { | |
invisible(withr::with_seed(seed, rnorm(1))) | |
} | |
my_bad_function <- function() { | |
invisible(rnorm(1)) | |
} | |
# good pattern | |
set.seed(123) | |
good_first_rand <- rnorm(1) |> print() |
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 all links on a webpage | |
## GOAL 1 : list all links | |
## GOAL 2: test all links | |
# for the anatomy of a url, I referred to | |
# https://www.netmeister.org/blog/urls.html | |
# load libraries ---------------------------------------------------------- |
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
function(x, y) regmatches(x, regexpr(y, x)) |
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
datapackage_json <- | |
jsonlite::read_json("https://raw.githubusercontent.com/inbo/etn/main/inst/assets/datapackage.json") | |
datapackage_tbl <- | |
datapackage_json |> | |
purrr::chuck("resources") |> | |
purrr::map( | |
\(resource) purrr::set_names( | |
purrr::chuck(resource, "schema", "fields"), | |
purrr::chuck(resource, "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
library(dplyr) | |
check_presence <- | |
function(scientificName = c('Vulpes vulpes', 'Pica pica'), | |
country = "BE") { | |
purrr::map( | |
scientificName, | |
~ rgbif::occ_data( | |
scientificName = .x, | |
country = country, |
NewerOlder