Skip to content

Commit

Permalink
Update mx_api.R
Browse files Browse the repository at this point in the history
  • Loading branch information
YaoxiangLi committed Oct 3, 2024
1 parent 389b2e5 commit 36290cb
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions R/mx_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
#' @export
#'
#' @examples
#' if(interactive()){
#' mx_data <- mx_api_content(from_date = "2020-01-01",
#' to_date = "2020-01-07")
#' if (interactive()) {
#' mx_data <- mx_api_content(
#' from_date = "2020-01-01",
#' to_date = "2020-01-07"
#' )
#' }
#' @importFrom dplyr %>%
#' @importFrom rlang .data
Expand All @@ -38,7 +40,6 @@ mx_api_content <- function(from_date = "2013-01-01",
clean = TRUE,
server = "medrxiv",
include_info = FALSE) {

# Check that the user is connected to the internet
internet_check()

Expand All @@ -57,7 +58,7 @@ mx_api_content <- function(from_date = "2013-01-01",
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 @@ -80,11 +81,14 @@ mx_api_content <- function(from_date = "2013-01-01",
for (cursor in 0:pages) {
page <- cursor * 100

page_link <- api_link(server,
from_date,
to_date,
format(page,
scientific = FALSE))
page_link <- api_link(
server,
from_date,
to_date,
format(page,
scientific = FALSE
)
)

tmp <- api_to_df(page_link)

Expand All @@ -99,8 +103,10 @@ mx_api_content <- function(from_date = "2013-01-01",
message("Number of records retrieved from API: ", nrow(df))

if (nrow(df) != count) {
message(paste0("The estimated \"total number\" as per the metadata ", #nocov
"can sometimes be artificially inflated.")) #nocov
message(paste0(
"The estimated \"total number\" as per the metadata ", # nocov
"can sometimes be artificially inflated."
)) # nocov
}

if (clean == TRUE) {
Expand Down Expand Up @@ -139,8 +145,8 @@ mx_api_content <- function(from_date = "2013-01-01",
#' @export
#'
#' @examples
#' if(interactive()){
#' mx_data <- mx_api_doi("10.1101/2020.02.25.20021568")
#' if (interactive()) {
#' mx_data <- mx_api_doi("10.1101/2020.02.25.20021568")
#' }
#' @importFrom dplyr %>%
#' @importFrom rlang .data
Expand Down

0 comments on commit 36290cb

Please sign in to comment.