Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
4052177
Stub based on `get_tags()`
Mar 19, 2026
8d3fa02
Repair names, mock a tag_serial_number: planned to be returned by vie…
Apr 28, 2026
e6a74b9
Switch to View, add subqueries
May 4, 2026
29b4d08
Name repair no longer needed with view
May 4, 2026
8d9828a
Tag serial number is included in new view
May 4, 2026
52f2990
Style
PietrH May 4, 2026
1a86e32
Add subquery logic
PietrH May 4, 2026
8b5a61b
Declare queriable columns as arguments
May 4, 2026
0c87cef
Stub tests
PietrH May 4, 2026
265ad7e
Query the right column, comment out client code
May 4, 2026
c1492e5
Returns data.frame, not a tibble
May 4, 2026
1d16897
rename return object, return as tibble to be consistent
May 4, 2026
ed8af4a
Move client code to client.
May 4, 2026
ad6c1ce
Style
PietrH May 4, 2026
254a2b1
roxygen2 documents
May 4, 2026
653ada4
devtools::document()
May 4, 2026
7573c5e
Files added by VLIZ RStudio server
May 4, 2026
eab8a40
Merge branch '126-get_archival_data_uuid' of https://github.com/inbo/…
PietrH May 4, 2026
581dd13
Add NEWS item
PietrH May 4, 2026
0c16b29
Up dev version
PietrH May 4, 2026
ee7cd2a
Merge branch 'main' into 126-get_archival_data_uuid
PietrH May 4, 2026
b08f0d6
up dev version
PietrH May 4, 2026
fb3b2b3
Test for returned object contents
PietrH May 4, 2026
80d5334
Test case insensitivity
PietrH May 4, 2026
4050353
animal_project_code should be case insensitive
PietrH May 4, 2026
982f4b4
name arguments for readability
PietrH May 4, 2026
777b0db
Merge pull request #145 from inbo/126-get_archival_data_uuid
PietrH May 4, 2026
caba45c
up dev number: trigger deployment
PietrH May 4, 2026
7e360fc
Declare min R4.1 required
PietrH May 4, 2026
9772e72
Test for minimum required R version
PietrH May 4, 2026
b36ee95
Refer to issue.
PietrH May 4, 2026
1b48dd7
Switch to native pipes.
PietrH May 4, 2026
2dcfb24
Remove pipe import: accidental replace all
PietrH May 4, 2026
2b52665
devtools::document()
PietrH May 4, 2026
47f16b1
Use native pipes
PietrH May 4, 2026
7df1785
Fix typo
May 4, 2026
bad7693
Update readme for native pipes
May 4, 2026
de109b6
Add magrittr pipe, for injection
PietrH May 4, 2026
d738d60
Merge branch '147-up-minimum-r' of https://github.com/inbo/etnservice…
PietrH May 4, 2026
dad95d3
Merge pull request #148 from inbo/147-up-minimum-r
PietrH May 4, 2026
2b2017c
Merge pull request #150 from inbo/147-up-minimum-r
PietrH May 4, 2026
2d96f5b
Up dev number: trigger test deployment
PietrH May 4, 2026
27771c9
Merge branch 'live-test' of https://github.com/inbo/etnservice into l…
PietrH May 4, 2026
e8a08d4
Refer to PR instead of Issue
PietrH May 5, 2026
3a5a038
Switch to named injection in base pipes
PietrH May 5, 2026
d7dade1
Merge branch '147-up-minimum-r' of https://github.com/inbo/etnservice…
PietrH May 5, 2026
b281214
Style
PietrH May 5, 2026
6fb9350
Increase precision in R version, follow example set by dplyr
PietrH May 5, 2026
4b874da
Merge branch '147-up-minimum-r' of https://github.com/inbo/etnservice…
PietrH May 5, 2026
7219f47
Merge branch 'live-test' into 147-up-minimum-r
PietrH May 5, 2026
e842086
Revert "Merge branch 'live-test' into 147-up-minimum-r"
PietrH May 5, 2026
203f381
Set R4.1.0 runner to older Ubuntu runner for C++ R toolchain availabi…
PietrH May 5, 2026
18a6361
Windows has odbc drivers bundled
PietrH May 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check-lite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: '3.6.3'}
- {os: windows-latest, r: '4.1.0'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Description: Provides API endpoints to the European Tracking Network.
License: MIT + file LICENSE
URL: https://github.com/inbo/etnservice
BugReports: https://github.com/inbo/etnservice/issues
Depends:
R (>= 4.1.0)
Imports:
arrow,
assertthat,
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export(list_scientific_names)
export(list_station_names)
export(list_tag_serial_numbers)
export(validate_login)
importFrom(dplyr,"%>%")
importFrom(dplyr,.data)
importFrom(dplyr,distinct)
importFrom(dplyr,filter)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# etnservice (development version)
- The function `write_dwc()` has been updated in the `etn` package and is no longer needed in `etnservice`. (#141)
- The `jsonlite` package is no longer a direct dependency, it is only used by a maintenance script. (#144)
- etnservice now relies on R >= 4.1.0 and uses base pipes (`|>` rather than `%>%`) (#151).
# etnservice 0.6.0
- Added `get_receiver_logs()` to fetch receiver logs from the database. The data is returned as a tibble with a column with logs in JSON format. (#117)

Expand Down
1 change: 0 additions & 1 deletion R/etnservice-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"_PACKAGE"

## usethis namespace: start
#' @importFrom dplyr %>%
#' @importFrom dplyr .data
#' @importFrom dplyr distinct
#' @importFrom dplyr filter
Expand Down
2 changes: 1 addition & 1 deletion R/get_acoustic_deployments.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ get_acoustic_deployments <- function(

# Sort data
deployments <-
deployments %>%
deployments |>
dplyr::arrange(
.data$acoustic_project_code,
factor(.data$station_name, levels = list_station_names(credentials)),
Expand Down
2 changes: 1 addition & 1 deletion R/get_acoustic_detections.R
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ get_acoustic_detections <- function(credentials = list(

# Sort data (faster than in SQL)
detections <-
detections %>%
detections |>
dplyr::arrange(
factor(.data$acoustic_tag_id, levels = list_acoustic_tag_ids(credentials)),
.data$date_time
Expand Down
3 changes: 2 additions & 1 deletion R/get_acoustic_detections_page.R
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ get_acoustic_detections_page <- function(credentials = list(
# Apply mapping -----
if (!count) {
# No need to apply mapping if we're only returning the number of records
returned_page <- returned_page %>%
returned_page <-
returned_page |>
dplyr::transmute(
detection_id = .data$detection_id_pk,
date_time = .data$datetime,
Expand Down
2 changes: 1 addition & 1 deletion R/get_acoustic_projects.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ get_acoustic_projects <- function(credentials = list(

# Sort data
projects <-
projects %>%
projects |>
dplyr::arrange(.data$project_code)

dplyr::as_tibble(projects)
Expand Down
2 changes: 1 addition & 1 deletion R/get_acoustic_receivers.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ get_acoustic_receivers <- function(credentials = list(

# Sort data
receivers <-
receivers %>%
receivers |>
dplyr::arrange(.data$receiver_id)

# Close connection
Expand Down
2 changes: 1 addition & 1 deletion R/get_animal_projects.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ get_animal_projects <- function(credentials = list(

# Sort data
projects <-
projects %>%
projects |>
dplyr::arrange(.data$project_code)

dplyr::as_tibble(projects)
Expand Down
20 changes: 10 additions & 10 deletions R/get_animals.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,24 +223,24 @@ get_animals <- function(credentials = list(

# Collapse tag information, to obtain one row = one animal
tag_cols <-
animals %>%
dplyr::select(dplyr::starts_with("tag"), dplyr::starts_with("acoustic_tag_id")) %>%
animals |>
dplyr::select(dplyr::starts_with("tag"), dplyr::starts_with("acoustic_tag_id")) |>
names()
other_cols <-
animals %>%
dplyr::select(-dplyr::starts_with("tag"), -dplyr::starts_with("acoustic_tag_id")) %>%
animals |>
dplyr::select(-dplyr::starts_with("tag"), -dplyr::starts_with("acoustic_tag_id")) |>
names()
animals <-
animals %>%
dplyr::group_by_at(other_cols) %>%
dplyr::summarize_at(tag_cols, paste, collapse = ",") %>% # Collapse multiple tags by comma
dplyr::ungroup() %>%
dplyr::mutate_at(tag_cols, gsub, pattern = "NA", replacement = "") %>% # Use "" instead of "NA"
animals |>
dplyr::group_by_at(other_cols) |>
dplyr::summarize_at(tag_cols, paste, collapse = ",") |> # Collapse multiple tags by comma
dplyr::ungroup() |>
dplyr::mutate_at(tag_cols, gsub, pattern = "NA", replacement = "") |> # Use "" instead of "NA"
dplyr::select(names(animals)) # Use the original column order

# Sort data
animals <-
animals %>%
animals |>
dplyr::arrange(
.data$animal_project_code,
.data$release_date_time,
Expand Down
2 changes: 1 addition & 1 deletion R/get_cpod_projects.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ get_cpod_projects <- function(credentials = list(

# Sort data
projects <-
projects %>%
projects |>
dplyr::arrange(.data$project_code)
# Close connection
DBI::dbDisconnect(connection)
Expand Down
2 changes: 1 addition & 1 deletion R/get_receiver_logs.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ get_receiver_logs <- function(credentials = list(

# Sort data
receiver_logs <-
receiver_logs %>%
receiver_logs |>
dplyr::arrange(factor(
.data$deployment_id, levels = list_deployment_ids(credentials)
))
Expand Down
2 changes: 1 addition & 1 deletion R/get_tags.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ get_tags <- function(credentials = list(

# Sort data
tags <-
tags %>%
tags |>
dplyr::arrange(factor(.data$tag_serial_number, levels = list_tag_serial_numbers(credentials)))

dplyr::as_tibble(tags)
Expand Down
4 changes: 2 additions & 2 deletions R/get_version.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ get_version <- function() {
# Get all functions from etnservice and their code
fn_names <- ls(envir = getNamespace("etnservice"))
fn_code <- purrr::map(fn_names,
~ get(.x, envir = getNamespace("etnservice"))) %>%
purrr::map(deparse) %>%
~ get(.x, envir = getNamespace("etnservice"))) |>
purrr::map(deparse) |>
purrr::set_names(fn_names)
# Calculate hashes for the functions, report on the installed version of
# etnservice
Expand Down
18 changes: 9 additions & 9 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ check_credentials <- function(credentials) {
#' @family helper functions
#' @noRd
extract_temp_key <- function(response) {
response %>%
httr::content(as = "text") %>%
response |>
httr::content(as = "text") |>
stringr::str_extract("(?<=tmp\\/).{15}(?=\\/)")
}

Expand All @@ -188,13 +188,13 @@ extract_temp_key <- function(response) {
#' @noRd
#' @examples
#' \dontrun{
#' etn:::extract_temp_key(response) %>% get_val()
#' etn:::extract_temp_key(response) |> get_val()
#' }
#'
#' # using the opencpu test instance
#' api_url <- "https://cloud.opencpu.org/ocpu/library/stats/R/rnorm"
#' httr::POST(api_url, body = list(n = 10, mean = 5)) %>%
#' extract_temp_key() %>%
#' httr::POST(api_url, body = list(n = 10, mean = 5)) |>
#' extract_temp_key() |>
#' get_val(api_domain = "https://cloud.opencpu.org/ocpu")
get_val <- function(temp_key, api_domain = "https://opencpu.lifewatch.be") {
httr::GET(
Expand All @@ -203,9 +203,9 @@ get_val <- function(temp_key, api_domain = "https://opencpu.lifewatch.be") {
"tmp/{temp_key}/R/.val/rds",
.sep = "/"
)
) %>%
httr::content(as = "raw") %>%
rawConnection() %>%
gzcon() %>%
) |>
httr::content(as = "raw") |>
rawConnection() |>
gzcon() |>
readRDS()
}
9 changes: 4 additions & 5 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ This is a basic example which shows you how adress the API directly:

```{r example, eval = FALSE}
library(httr2) # to talk to the internet
library(magrittr) # to use pipes
library(askpass) # to safly enter a password in R

# To access the ETN database, we need a login (username + password). We'll ask
Expand All @@ -69,16 +68,16 @@ username <- "<your-username-here>"
endpoint <- "https://opencpu.lifewatch.be/library/etnservice/R/list_scientific_names"
# Request the result of the function to be a json, and put in a request
response <-
httr2::request(endpoint) %>%
httr2::request(endpoint) |>
## In this case we'll request the data in JSON format and parse it
httr2::req_url_path_append("json") %>%
httr2::req_url_path_append("json") |>
httr2::req_body_json(
list(credentials = list(username = username,
password = askpass::askpass()))
) %>%
) |>
httr2::req_perform()
# Take the response of the server, and convert it into an R object we can use
response %>%
response |>
httr2::resp_body_json(simplifyVector = TRUE)

```
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ This is a basic example which shows you how adress the API directly:

``` r
library(httr2) # to talk to the internet
library(magrittr) # to use pipes
library(askpass) # to safly enter a password in R

# To access the ETN database, we need a login (username + password). We'll ask
Expand All @@ -65,16 +64,16 @@ username <- "<your-username-here>"
endpoint <- "https://opencpu.lifewatch.be/library/etnservice/R/list_scientific_names"
# Request the result of the function to be a json, and put in a request
response <-
httr2::request(endpoint) %>%
httr2::request(endpoint) |>
## In this case we'll request the data in JSON format and parse it
httr2::req_url_path_append("json") %>%
httr2::req_url_path_append("json") |>
httr2::req_body_json(
list(credentials = list(username = username,
password = askpass::askpass()))
) %>%
) |>
httr2::req_perform()
# Take the response of the server, and convert it into an R object we can use
response %>%
response |>
httr2::resp_body_json(simplifyVector = TRUE)
```

Expand Down
4 changes: 2 additions & 2 deletions inst/postman-helpers/find-postman-test-mismatch.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ assertthat::assert_that(!httr2::resp_is_error(response))
## extract current expectation --------------------------------------------
expectation <- readr::read_lines(
glue::glue("tests/postman/test-{fn_to_test}.js")
) %>%
) |>
grep("pm.expect(jsonData).to.include.members(",
.,
x = _,
fixed = TRUE,
value = TRUE) |>
stringr::str_extract_all('(?<=")[^,]*?(?=\\")') |>
Expand Down
20 changes: 10 additions & 10 deletions inst/postman-helpers/postman-export-to-js.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ export <- jsonlite::read_json("tests/postman/etnservice.postman_collection.json"
# helper to get test script out -------------------------------------------

get_script <- function(event) {
event[[1]] %>%
pluck("script") %>%
pluck("exec") %>%
event[[1]] |>
pluck("script") |>
pluck("exec") |>
paste(collapse = "\n")
}

# get names and scripts and write out -------------------------------------

request_names <-
export %>%
pluck("item") %>%
export |>
pluck("item") |>
map_chr(~ pluck(.x, "name"))

export %>%
pluck("item") %>%
map(~ pluck(.x, "event")) %>%
map(get_script) %>%
set_names(request_names) %>%
export |>
pluck("item") |>
map(~ pluck(.x, "event")) |>
map(get_script) |>
set_names(request_names) |>
walk2(request_names, ~ readr::write_lines(.x, file.path(
"tests", "postman", paste0("test-", .y, ".js")
)))
18 changes: 9 additions & 9 deletions tests/testthat/test-get_acoustic_deployments.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test_that("get_acoustic_deployments() returns a tibble", {

test_that("get_acoustic_deployments() returns unique deployment_id", {
df <- get_acoustic_deployments(credentials)
expect_equal(nrow(df), nrow(df %>% distinct(deployment_id)))
expect_equal(nrow(df), nrow(df |> distinct(deployment_id)))
})

test_that("get_acoustic_deployments() returns the expected columns", {
Expand Down Expand Up @@ -81,7 +81,7 @@ test_that("get_acoustic_deployments() allows selecting on deployment_id", {
single_select <- 1437 # From demer
single_select_df <- get_acoustic_deployments(credentials, deployment_id = single_select)
expect_equal(
single_select_df %>% distinct(deployment_id) %>% pull(),
single_select_df |> distinct(deployment_id) |> pull(),
c(single_select)
)
expect_gt(nrow(single_select_df), 0)
Expand All @@ -90,7 +90,7 @@ test_that("get_acoustic_deployments() allows selecting on deployment_id", {
multi_select <- c("1437", 1588) # Characters are allowed
multi_select_df <- get_acoustic_deployments(credentials, deployment_id = multi_select)
expect_equal(
multi_select_df %>% distinct(deployment_id) %>% pull() %>% sort(),
multi_select_df |> distinct(deployment_id) |> pull() |> sort(),
c(as.integer(multi_select)) # Output will be all integer
)
expect_gt(nrow(multi_select_df), nrow(single_select_df))
Expand All @@ -105,7 +105,7 @@ test_that("get_acoustic_deployments() allows selecting on receiver_id", {
single_select <- "VR2W-124070" # From demer
single_select_df <- get_acoustic_deployments(credentials, receiver_id = single_select)
expect_equal(
single_select_df %>% distinct(receiver_id) %>% pull(),
single_select_df |> distinct(receiver_id) |> pull(),
c(single_select)
)
expect_gt(nrow(single_select_df), 0)
Expand All @@ -114,7 +114,7 @@ test_that("get_acoustic_deployments() allows selecting on receiver_id", {
multi_select <- c("VR2W-124070", "VR2W-124078")
multi_select_df <- get_acoustic_deployments(credentials, receiver_id = multi_select)
expect_equal(
multi_select_df %>% distinct(receiver_id) %>% pull() %>% sort(),
multi_select_df |> distinct(receiver_id) |> pull() |> sort(),
c(multi_select)
)
expect_gt(nrow(multi_select_df), nrow(single_select_df))
Expand All @@ -129,7 +129,7 @@ test_that("get_acoustic_deployments() allows selecting on acoustic_project_code"
single_select <- "demer"
single_select_df <- get_acoustic_deployments(credentials, acoustic_project_code = single_select)
expect_equal(
single_select_df %>% distinct(acoustic_project_code) %>% pull(),
single_select_df |> distinct(acoustic_project_code) |> pull(),
c(single_select)
)
expect_gt(nrow(single_select_df), 0)
Expand All @@ -144,7 +144,7 @@ test_that("get_acoustic_deployments() allows selecting on acoustic_project_code"
multi_select <- c("demer", "dijle")
multi_select_df <- get_acoustic_deployments(credentials, acoustic_project_code = multi_select)
expect_equal(
multi_select_df %>% distinct(acoustic_project_code) %>% pull() %>% sort(),
multi_select_df |> distinct(acoustic_project_code) |> pull() |> sort(),
c(multi_select)
)
expect_gt(nrow(multi_select_df), nrow(single_select_df))
Expand All @@ -159,7 +159,7 @@ test_that("get_acoustic_deployments() allows selecting on station_name", {
single_select <- "de-9" # From demer
single_select_df <- get_acoustic_deployments(credentials, station_name = single_select)
expect_equal(
single_select_df %>% distinct(station_name) %>% pull(),
single_select_df |> distinct(station_name) |> pull(),
c(single_select)
)
expect_gt(nrow(single_select_df), 0)
Expand All @@ -168,7 +168,7 @@ test_that("get_acoustic_deployments() allows selecting on station_name", {
multi_select <- c("de-10", "de-9") # Note that sort() will put de-10 before de-9
multi_select_df <- get_acoustic_deployments(credentials, station_name = multi_select)
expect_equal(
multi_select_df %>% distinct(station_name) %>% pull() %>% sort(),
multi_select_df |> distinct(station_name) |> pull() |> sort(),
c(multi_select)
)
expect_gt(nrow(multi_select_df), nrow(single_select_df))
Expand Down
Loading
Loading