Skip to content

Commit

Permalink
Merge pull request #66 from stitam/wf
Browse files Browse the repository at this point in the history
Revert "Disable GitHub workflows"
  • Loading branch information
stitam authored Feb 16, 2024
2 parents f7d8810 + fe7eccb commit cf1ebfd
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ README.Rmd
/cache/

# scripts that are not part of the package
scripts/
scripts
50 changes: 50 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from
# https://github.com/r-lib/actions/blob/v2-branch/examples/check-standard.yaml

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v3

- 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-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
33 changes: 33 additions & 0 deletions .github/workflows/check-pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
on:
push:
branches:
- master
pull_request:
branches:
- master

name: check-pkgdown

jobs:
check_pkgdown:
runs-on: ubuntu-22.04

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3
- uses: r-lib/actions/setup-r@v2
with:
r-version: 'release'
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::devtools, any::pkgdown

- name: Install dependencies
run: devtools::install_github("https://github.com/ropensci-org/rotemplate")
shell: Rscript {0}

- name: Check pkgdown
run: pkgdown::check_pkgdown()
shell: Rscript {0}
51 changes: 51 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Workflow copied from
https://github.com/r-lib/actions/blob/v2-branch/examples/test-coverage.yaml

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
needs: coverage

- name: Test coverage
run: |
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
)
shell: Rscript {0}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ Maintainer: Tamas Stirling <[email protected]>
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Depends:
R (>= 3.5.0)
Imports:
curl,
dplyr,
httr,
jsonlite,
plyr,
rentrez,
stringi,
stringr,
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export(ncbi_link_uid)
export(ncbi_parse)
export(ncbi_parse_assembly_xml)
export(ncbi_parse_biosample_txt)
export(parse_gb_header)
export(parse_report)
importFrom(curl,curl_download)
importFrom(curl,handle_setopt)
Expand Down
5 changes: 4 additions & 1 deletion R/ncbi_get_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#' API queries?
#' @param parse logical; should the function attempt to parse the output into a
#' tibble?
#' @param mc_cores integer; number of cores to use for parallel processing. Only
#' used if \code{parse = TRUE}.
#' @param verbose logical; Should verbose messages be printed to console?
#' @return If \code{parse = FALSE} the function will return an object of class
#' \code{ncbi_meta}, which is a character vector with some extra information
Expand Down Expand Up @@ -42,6 +44,7 @@ ncbi_get_meta <- function(
batch_size = 100,
use_history = TRUE,
parse = TRUE,
mc_cores = NULL,
verbose = getOption("verbose")
) {
if ("ncbi_uid" %in% class(query)) {
Expand Down Expand Up @@ -159,7 +162,7 @@ ncbi_get_meta <- function(
if (verbose) {
message("Attempting to parse retrieved metadata.")
}
res_parsed <- ncbi_parse(meta = res, verbose = verbose)
res_parsed <- ncbi_parse(meta = res, mc_cores = mc_cores, verbose = verbose)
if (all("data.frame" %in% class(res_parsed))) {
out <- dplyr::bind_rows(res_parsed)
if (verbose) message("Done.")
Expand Down
7 changes: 1 addition & 6 deletions R/ncbi_parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @param db character; the NCBI database from which the data was retrieved.
#' @param format character; the format of the data set. Currently only
#' \code{"xml"} is supported.
#' @param mc_cores integer; number of cores to use for parallel processing.
#' @param mc_cores integer; Number of cores to use for parallel processing.
#' @param verbose logical; Should verbose messages be printed to console?
#' @return a tibble.
#' @details This function is integrated into \code{ncbi_get_meta()} and is
Expand Down Expand Up @@ -73,11 +73,6 @@ ncbi_parse <- function(
}
db <- match.arg(db, choices = c("assembly", "biosample"))
format <- match.arg(format, choices = c("xml"))
if (is.null(mc_cores)) {
mc_cores <- max(parallel::detectCores() - 1, 1)
} else {
mc_cores <- as.integer(mc_cores)
}
f <- get(paste("ncbi_parse", db, format, sep = "_"))
if (db == "assembly" && format == "xml") {
out <- f(meta, verbose = verbose)
Expand Down
16 changes: 6 additions & 10 deletions R/ncbi_parse_biosample_xml.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ ncbi_parse_biosample_xml <- function(
if (verbose) message("No BioSample metadata to parse.")
return(NA_character_)
}
if (is.null(mc_cores)) {
mc_cores <- max(parallel::detectCores() - 1, 1)
} else {
mc_cores <- as.integer(mc_cores)
}
mc_cores <- get_mc_cores(mc_cores, verbose = verbose)
biosample_df <- data.frame()
if (verbose) message("Attempting to parse BioSample XMLs.")
for (i in seq_along(biosample_xml)) {
Expand Down Expand Up @@ -69,14 +65,14 @@ ncbi_parse_biosample_xml <- function(
}
if (verbose) message("Successful.")
out <- dplyr::bind_rows(out)
out <- dplyr::relocate(out, biosample_uid)
out <- dplyr::relocate(out, biosample, .after = biosample_uid)
out <- dplyr::relocate(out, "biosample_uid")
out <- dplyr::relocate(out, "biosample", .after = "biosample_uid")
biosample_df <- dplyr::bind_rows(biosample_df, out)
}
out <- tibble::as_tibble(biosample_df)
out <- out[, order(unname(sapply(out, function(x) sum(is.na(x)))))]
out <- dplyr::relocate(out, biosample_uid)
out <- dplyr::relocate(out, biosample, .after = biosample_uid)
out <- dplyr::relocate(out, "biosample_uid")
out <- dplyr::relocate(out, "biosample", .after = "biosample_uid")
return(out)
}

Expand Down Expand Up @@ -138,7 +134,7 @@ ncbi_parse_biosample_xml_entry <- function(x, verbose = getOption("verbose")) {
}
if (all(c("geo", "geo_link") %in% names(out)) & nrow(out) == 1) {
if (grepl(out$geo, out$geo_link)) {
out <- dplyr::select(out, -geo_link)
out <- dplyr::select(out, -"geo_link")
}
}
if (nrow(out) > 1) {
Expand Down
66 changes: 0 additions & 66 deletions R/parse_gb_header.R

This file was deleted.

37 changes: 37 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,40 @@ validate_webseq_class <- function(x) {
testthat::expect_true(attr(x, "db") %in% ncbi_dbs())
}
}

#' Get number of processor cores
#'
#' @param mc_cores integer; Number of cores to use for parallel processing.
#' @param verbose logical; Should verbose messages be printed to console?
#' @noRd
get_mc_cores <- function(mc_cores, verbose = getOption("verbose")) {
if (is.null(mc_cores)) {
if (verbose) message(
"Number of cores not specified. Looking at 'Ncpu' option."
)
mc_cores <- getOption("Ncpu")
if (!is.null(mc_cores)) {
if (verbose) message("Found.")
} else {
if (verbose) message(
"Not found. Attempting to use all but one cores (at least 1)."
)
mc_cores <- max(parallel::detectCores() - 1, 1)
}
}
mc_cores <- as.integer(mc_cores)
if (!is.integer(mc_cores)) {
stop("Number of cores must be an integer.")
}
if (mc_cores < 1) {
stop("Number of cores must be at least 1.")
}
sys <- Sys.info()
if (mc_cores > 1 && sys[["sysname"]] == "Windows") {
if (verbose) message(
"'mc.cores' > 1 is not supported on Windows."
)
mc_cores <- 1
}
return(mc_cores)
}
4 changes: 4 additions & 0 deletions man/ncbi_get_meta.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ncbi_parse.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cf1ebfd

Please sign in to comment.