diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 2142c6e..67bf99e 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -13,7 +13,6 @@ name: R-CMD-check jobs: R-CMD-check: runs-on: ${{ matrix.config.os }} - name: ${{ matrix.config.os }} (${{ matrix.config.r }}) strategy: @@ -30,13 +29,19 @@ jobs: RSPM: ${{ matrix.config.rspm }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: r-lib/actions/setup-r@master + - uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} - - uses: r-lib/actions/setup-pandoc@master + - uses: r-lib/actions/setup-pandoc@v2 + + - name: Install system dependencies (Linux) + if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt-get install -y libcurl4-openssl-dev libssl-dev - name: Query dependencies run: | @@ -45,28 +50,26 @@ jobs: writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") shell: Rscript {0} - - name: Cache R packages + - name: Cache R packages (Linux and macOS) if: runner.os != 'Windows' - uses: actions/cache@v1 + uses: actions/cache@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 'cat(remotes::system_requirements("ubuntu", "20.04"), sep = "\n")') - - name: Install dependencies run: | remotes::install_deps(dependencies = TRUE) remotes::install_cran("rcmdcheck") shell: Rscript {0} + - name: Install missing packages on Windows + if: runner.os == 'Windows' + run: | + install.packages(c('curl', 'openssl', 'testthat', 'hms', 'dplyr', 'rlang', 'tibble', 'progress', 'remotes', 'rcmdcheck')) + shell: Rscript {0} + - name: Check env: _R_CHECK_CRAN_INCOMING_REMOTE_: false diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 3058d03..37b77e9 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -10,15 +10,20 @@ name: test-coverage jobs: test-coverage: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: r-lib/actions/setup-r@master + - uses: r-lib/actions/setup-r@v2 - - uses: r-lib/actions/setup-pandoc@master + - uses: r-lib/actions/setup-pandoc@v2 + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y libcurl4-openssl-dev libssl-dev - name: Query dependencies run: | @@ -28,19 +33,36 @@ jobs: shell: Rscript {0} - name: Cache R packages - uses: actions/cache@v1 + uses: actions/cache@v3 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- + key: ${{ runner.os }}-R-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ runner.os }}-R-${{ hashFiles('.github/R-version') }}-1- - name: Install dependencies run: | - install.packages(c("remotes")) + install.packages(c("remotes", "covr")) remotes::install_deps(dependencies = TRUE) - remotes::install_cran("covr") + shell: Rscript {0} + + - name: Check for missing packages + run: | + missing_pkgs <- setdiff(c("covr", "testthat"), rownames(installed.packages())) + if (length(missing_pkgs) > 0) { + cat("Missing packages:", paste(missing_pkgs, collapse = ", "), "\n") + install.packages(missing_pkgs) + } else { + cat("All required packages are installed.\n") + } + shell: Rscript {0} + + - name: Run tests + run: | + testthat::test_local() shell: Rscript {0} - name: Test coverage run: covr::codecov() shell: Rscript {0} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} diff --git a/R/mx_api.R b/R/mx_api.R index 674d7d8..986193d 100644 --- a/R/mx_api.R +++ b/R/mx_api.R @@ -39,12 +39,10 @@ mx_api_content <- function(from_date = "2013-01-01", server = "medrxiv", include_info = FALSE) { - # Check that the user is connected to the internet internet_check() # Check server - "%notin%" <- Negate("%in%") if (server %notin% c("medrxiv", "biorxiv")) { @@ -56,10 +54,10 @@ mx_api_content <- function(from_date = "2013-01-01", # Get descriptive details and page number details_link <- api_link(server, from_date, to_date, "0") - details <- api_to_df(details_link) count <- as.numeric(details$messages[1, 6]) + pages <- floor(count / 100) message("Estimated total number of records as per API metadata: ", count) @@ -69,14 +67,13 @@ mx_api_content <- function(from_date = "2013-01-01", dplyr::filter(doi == "") # Get data - pb <- - progress::progress_bar$new( - format = paste0( - "Downloading... [:bar] :current/:total ", - "(:percent) Est. time remaining: :eta" - ), - total = count - ) + pb <- progress::progress_bar$new( + format = paste0( + "Downloading... [:bar] :current/:total ", + "(:percent) Est. time remaining: :eta" + ), + total = count + ) pb$tick(0) @@ -99,12 +96,11 @@ mx_api_content <- function(from_date = "2013-01-01", } # Clean data - message("Number of records retrieved from API: ", nrow(df)) - if (nrow(df)!= count) { + if (nrow(df) != count) { message(paste0("The estimated \"total number\" as per the metadata ", #nocov - "can sometimes be artifically inflated.")) #nocov + "can sometimes be artificially inflated.")) #nocov } if (clean == TRUE) { diff --git a/R/mx_crosscheck.R b/R/mx_crosscheck.R index 944f479..ed92f9c 100644 --- a/R/mx_crosscheck.R +++ b/R/mx_crosscheck.R @@ -16,25 +16,31 @@ mx_crosscheck <- function() { internet_check() mx_info() - # Get number of unique records in the medRxiv archive --------------------- - + # Get number of unique records in the medRxiv archive base_link <- api_link("medrxiv", "2019-01-01", as.character(Sys.Date()), "0") - details <- api_to_df(base_link) - reference <- details$messages[1, 6] + # Ensure 'reference' is numeric + reference <- as.numeric(details$messages[1, 6]) + if (is.na(reference)) { + stop("Reference value is not numeric.") + } - # Get number of unique records extracted ---------------------------------- + # Get number of unique records extracted data <- suppressMessages(mx_search(mx_snapshot(), query = "*", deduplicate = FALSE )) - extracted <- nrow(data) + # Ensure 'extracted' is numeric + extracted <- as.numeric(nrow(data)) + if (is.na(extracted)) { + stop("Extracted value is not numeric.") + } diff <- reference - extracted - if (identical(reference, extracted) == TRUE) { + if (identical(reference, extracted)) { message("No records added/updated since last snapshot.") # nocov } else { message(paste0(