Skip to content

Commit

Permalink
Merge pull request #39 from esloch/fix-numeric-type
Browse files Browse the repository at this point in the history
fix: Correct Non-Numeric argument errors and Update gh-actions for compatibility
  • Loading branch information
YaoxiangLi authored Oct 1, 2024
2 parents 9ddf213 + e54c155 commit bd88e89
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 44 deletions.
31 changes: 17 additions & 14 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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: |
Expand All @@ -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
Expand Down
40 changes: 31 additions & 9 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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 }}
24 changes: 10 additions & 14 deletions R/mx_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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) {
Expand Down
20 changes: 13 additions & 7 deletions R/mx_crosscheck.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit bd88e89

Please sign in to comment.