Skip to content

Commit

Permalink
updated snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
YaoxiangLi committed Oct 25, 2024
1 parent ed28762 commit 8f02e00
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
41 changes: 32 additions & 9 deletions R/mx_snapshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,42 @@
#' mx_data <- mx_snapshot()
#' }
#'
mx_snapshot <- function(commit = "master") {
mx_info(commit)
mx_snapshot <- function(commit = "main") {

mx_data <- suppressMessages(data.table::fread(
paste0(
"https://raw.githubusercontent.com/",
"/mcguinlu/medrxivr-data/", commit, "/snapshot.csv"
),
showProgress = FALSE
))
# Get the base URL for the data repository
base_url <- paste0(
"https://github.com/YaoxiangLi/medrxivr-data/raw/refs/heads/", commit, "/"
)

# Generate a list of potential snapshot part files
# Assuming the files follow the pattern "snapshot_part1.csv", "snapshot_part2.csv", etc.
part_files <- paste0("snapshot_part", 1:20, ".csv")

# Initialize an empty list to store dataframes
df_list <- list()

# Try to read each file and add it to the list
for (part_file in part_files) {
url <- paste0(base_url, part_file)

# Attempt to read the file; skip if it doesn't exist
try({
mx_part <- suppressMessages(data.table::fread(url, showProgress = FALSE))
df_list[[length(df_list) + 1]] <- mx_part
}, silent = TRUE)
}


# Combine all the loaded parts into a single dataframe
if (length(df_list) == 0) {
stop("No data could be loaded. Please check the commit or data availability.")
}
mx_data <- dplyr::bind_rows(df_list)

# Reconstruct the link_page and link_pdf columns
mx_data$link_page <- paste0("https://www.medrxiv.org", mx_data$link)
mx_data$link_pdf <- paste0("https://www.medrxiv.org", mx_data$pdf)

# Return the combined dataframe
mx_data
}
2 changes: 1 addition & 1 deletion vignettes/building-complex-search-strategies.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Building complex search strategies"
author: "Luke A McGuinness"
author: "Yaoxiang Li"
date: "`r Sys.Date()`"
output:
rmarkdown::html_document:
Expand Down
2 changes: 1 addition & 1 deletion vignettes/medrxiv-api.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Interacting with the Cold Spring Harbour Laboratory API"
author: "Luke A McGuinness"
author: "Yaoxiang Li"
date: "`r Sys.Date()`"
output:
rmarkdown::html_document:
Expand Down
6 changes: 3 additions & 3 deletions vignettes/medrxivr.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Get started"
author: "Luke A McGuinness"
author: "Yaoxiang Li"
date: "`r Sys.Date()`"
output:
rmarkdown::html_document:
Expand Down Expand Up @@ -31,10 +31,10 @@ The goal of the `medrxivr` R package is two-fold. In the first instance, it prov

## Installation

You can install the development version of this package using:
You can install the stable version of this package using:

``` {r}
devtools::install_github("mcguinlu/medrxivr")
install.packages("medrxivr")
library(medrxivr)
```

Expand Down

0 comments on commit 8f02e00

Please sign in to comment.