From 1a8bde172a3ba26973aceaafb4cdf03f4d0dbc18 Mon Sep 17 00:00:00 2001 From: naja Date: Sun, 16 Jan 2022 14:52:21 +0100 Subject: [PATCH 1/3] Catch missing pmcid json elements #45 --- R/annotations_by_id.R | 31 ++++++++++++++----------- tests/testthat/test_annotations_by_id.r | 5 ++++ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/R/annotations_by_id.R b/R/annotations_by_id.R index 1de41cb..175d4dc 100644 --- a/R/annotations_by_id.R +++ b/R/annotations_by_id.R @@ -31,7 +31,7 @@ #' annotations_by_id(c("MED:28585529", "PMC:PMC1664601")) #' } #' @export -epmc_annotations_by_id <- function(ids = NULL){ +epmc_annotations_by_id <- function(ids = NULL) { # input validation stopifnot(!is.null(ids)) # remove empty characters @@ -50,21 +50,24 @@ epmc_annotations_by_id_ <- function(ids = NULL, .pb = NULL) { inherits(.pb, "Progress") && (.pb$i < .pb$n)) .pb$tick()$print() - args <- list( - articleIds = ids, - format = "json" - ) - req <- rebi_GET(path = c(anno_path(), "annotationsByArticleIds"), query = args) + args <- list(articleIds = ids, + format = "json") + req <- + rebi_GET(path = c(anno_path(), "annotationsByArticleIds"), + query = args) # API sometimes returns empty response when nothing is found, # but id is syntactically correct - if(length(req) != 0) { - out <- tibble::tibble(source = req[["source"]], - ext_id = req[["extId"]], - pmcid = req[["pmcid"]], - annotations = req[["annotations"]]) - tidyr::unnest( - tidyr::unnest(out, .data$annotations), - .data$tags) + if (length(req) != 0) { + out <- tibble::tibble( + source = req[["source"]], + ext_id = req[["extId"]], + pmcid = dplyr::if_else( + is.null(req[["pmcid"]]), NA_character_, req[["pmcid"]] + ), + annotations = req[["annotations"]] + ) + tidyr::unnest(tidyr::unnest(out, .data$annotations), + .data$tags) } else { NULL } diff --git a/tests/testthat/test_annotations_by_id.r b/tests/testthat/test_annotations_by_id.r index ed1461f..b030c68 100644 --- a/tests/testthat/test_annotations_by_id.r +++ b/tests/testthat/test_annotations_by_id.r @@ -5,14 +5,19 @@ test_that("epmc_epmc_annotations_by_id returns", { a <- epmc_annotations_by_id("MED:28585529") b <- epmc_annotations_by_id(c("MED:28585529", "PMC:PMC1664601")) c <- epmc_annotations_by_id(c("MED:28585533", "MED:2858553366")) + # missing pmcid json element + d <- epmc_annotations_by_id("MED:10566658") # correct dimensions and class expect_output(str(a), "tbl_df") expect_output(str(b), "tbl_df") expect_output(str(c), "tbl_df") + expect_output(str(d), "tbl_df") + expect_equal(length(unique(b$ext_id)), 2) expect_equal(length(unique(c$ext_id)), 1) + expect_true(unique(is.na(d$pmcid))) # fails as expected expect_error(epmc_annotations_by_id("dd")) From 4d8a3efd4f34f6e94db0b57880b053ace4a3cbe3 Mon Sep 17 00:00:00 2001 From: naja Date: Sun, 16 Jan 2022 14:56:38 +0100 Subject: [PATCH 2/3] Update GA to r-lib check standard --- .github/workflows/R-CMD-check.yaml | 74 ++++++++---------------------- 1 file changed, 18 insertions(+), 56 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index cea7ca2..998dfcb 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -1,14 +1,10 @@ -# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag. -# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: - branches: - - main - - master + branches: [main, master] pull_request: - branches: - - main - - master + branches: [main, master] name: R-CMD-check @@ -22,64 +18,30 @@ jobs: fail-fast: false matrix: config: + - {os: macOS-latest, r: 'release'} - {os: windows-latest, r: 'release'} - - {os: macOS-latest, r: 'release'} - - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - - {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest", http-user-agent: "R/4.1.0 (ubuntu-20.04) R (4.1.0 x86_64-pc-linux-gnu x86_64 linux-gnu) on GitHub Actions" } + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} env: - R_REMOTES_NO_ERRORS_FROM_WARNINGS: true - RSPM: ${{ matrix.config.rspm }} GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true - - uses: r-lib/actions/setup-pandoc@v1 - - - name: Query dependencies - run: | - install.packages('remotes') - saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) - writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") - shell: Rscript {0} - - - name: Restore R package cache - uses: actions/cache@v2 + - uses: r-lib/actions/setup-r-dependencies@v2 with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - - - name: Install system dependencies - if: runner.os == 'Linux' - run: | - while read -r cmd - do - eval sudo $cmd - done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') + extra-packages: any::rcmdcheck + needs: check - - name: Install dependencies - run: | - remotes::install_deps(dependencies = TRUE) - remotes::install_cran("rcmdcheck") - shell: Rscript {0} - - - name: Check - env: - _R_CHECK_CRAN_INCOMING_REMOTE_: false - run: | - options(crayon.enabled = TRUE) - rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") - shell: Rscript {0} - - - name: Upload check results - if: failure() - uses: actions/upload-artifact@main - with: - name: ${{ runner.os }}-r${{ matrix.config.r }}-results - path: check + - uses: r-lib/actions/check-r-package@v2 From 32d5229b57b0a1e92ef457139b5192b54b66ffe3 Mon Sep 17 00:00:00 2001 From: naja Date: Sun, 16 Jan 2022 15:05:16 +0100 Subject: [PATCH 3/3] Remove unneeded file --- appveyor.yml | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 7d1c45b..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,41 +0,0 @@ -# DO NOT CHANGE the "init" and "install" sections below - -# Download script file from GitHub -init: - ps: | - $ErrorActionPreference = "Stop" - Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" - Import-Module '..\appveyor-tool.ps1' - -install: - ps: Bootstrap - -# Adapt as necessary starting from here - -build_script: - - travis-tool.sh install_deps - -test_script: - - travis-tool.sh run_tests - -on_failure: - - travis-tool.sh dump_logs - -artifacts: - - path: '*.Rcheck\**\*.log' - name: Logs - - - path: '*.Rcheck\**\*.out' - name: Logs - - - path: '*.Rcheck\**\*.fail' - name: Logs - - - path: '*.Rcheck\**\*.Rout' - name: Logs - - - path: '\*_*.tar.gz' - name: Bits - - - path: '\*_*.zip' - name: Bits