library(tidyverse)
# Example function of sending multiple scientificNames to rgbif::occ_data()
fetch_species_for_dimi <-
function(scientificName = c("Vulpes vulpes", "Puma concolor"),
country = "BE") {
purrr::map(
scientificName,
~ rgbif::occ_data(
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, |
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
first_df <- tibble::tibble(ids = c("id1", "id2", "id3"), labels = c("label1", "label2", "label3")) | |
second_df <- tibble::tibble(id1 = 1:3, id2 = 3:5, id3 = letters[6:8]) | |
dplyr::rename_with(second_df, ~ first_df$labels[match(.x, first_df$ids)]) |
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
tools::package_dependencies(packages = c("dplyr", | |
"tidyr", | |
"readr", | |
"stringr", | |
"purrr", | |
"here", | |
"tidylog", | |
"magrittr", | |
"sf", | |
"janitor", |
NewerOlder