Skip to content

Commit ea174b0

Browse files
authored
Merge pull request #28 from AlexsLemonade/jashapiro/example-vignette
Add intro vignette
2 parents 3526947 + 41e12d7 commit ea174b0

23 files changed

Lines changed: 1056 additions & 33 deletions

.Rbuildignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
^.claude$
12
^LICENSE\.md$
23
^ScPCAr\.Rproj$
34
^\.Rproj\.user$
45
^\.github$
56
^\.pre-commit-config\.yaml$
67
^_pkgdown\.yml$
78
^air\.toml$
9+
^claude.md$
810
^docs$
911
^pkgdown$
1012
^renv$
1113
^renv\.lock$
1214
^scpca_data$
1315
^typos.toml$
16+
^vignettes/articles$
17+
^vignettes/scpca_data$

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ po/*~
5252
rsconnect/
5353
.Rproj.user
5454
docs
55+
inst/doc

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ repos:
2323
rev: v6.0.0
2424
hooks:
2525
- id: check-added-large-files
26-
args: ["--maxkb=200"]
26+
args: ["--maxkb=400"]
2727
- id: file-contents-sorter
2828
files: '^\.Rbuildignore$'
2929
- id: end-of-file-fixer

DESCRIPTION

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@ Encoding: UTF-8
1515
Roxygen: list(markdown = TRUE)
1616
RoxygenNote: 7.3.2
1717
Suggests:
18+
devtools,
19+
ggplot2,
20+
here,
1821
httptest2,
22+
knitr,
23+
rmarkdown,
24+
scater,
25+
SingleCellExperiment,
1926
testthat (>= 3.2.0),
2027
withr
2128
Config/testthat/edition: 3
29+
VignetteBuilder: knitr
2230
Imports:
2331
curl,
2432
dplyr,
@@ -27,6 +35,7 @@ Imports:
2735
purrr,
2836
readr,
2937
stringr,
38+
tibble,
3039
tidyr,
3140
utils
3241
URL: https://alexslemonade.github.io/ScPCAr/

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export(get_project_libraries)
88
export(get_project_samples)
99
export(get_sample_info)
1010
export(scpca_projects)
11+
export(view_terms)
1112
import(httr2)
1213
importFrom(curl,curl_download)
1314
importFrom(dplyr,.data)

R/auth.R

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#' Get an authorization token from the ScPCA API
22
#'
3+
#' `get_auth()` allows obtaining an authorization token string from the ScPCA API,
4+
#' after providing an email address and agreeing to the terms of use.
5+
#'
6+
#' To view the terms of use before agreeing to them, use `view_terms()`, which opens the terms of use page in a web browser.
7+
#'
38
#' @param email The user's email address
49
#' @param agree A logical indicating whether the user agrees to the terms of service
510
#'
@@ -10,7 +15,7 @@
1015
#' @examples
1116
#' \dontrun{
1217
#' # Get a token (make sure to agree to the terms of service)
13-
#' auth_token <- get_auth("me@email.net", agree = TRUE)
18+
#' auth_token <- get_auth("your.email@example.com", agree = TRUE)
1419
#' }
1520
#'
1621
#' @export
@@ -27,3 +32,17 @@ get_auth <- function(email, agree = FALSE) {
2732

2833
response$id
2934
}
35+
36+
37+
#' View Terms of Use
38+
#' @export
39+
#' @rdname get_auth
40+
#' @examples
41+
#' \dontrun{
42+
#' view_terms()
43+
#' }
44+
view_terms <- function() {
45+
url <- "https://scpca.alexslemonade.org/terms-of-use"
46+
utils::browseURL(url)
47+
invisible(url)
48+
}

R/downloads.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ validate_format <- function(format) {
7878
#' @examples
7979
#' \dontrun{
8080
#' # Get a token first
81-
#' auth_token <- get_auth("me@email.net", agree = TRUE)
81+
#' auth_token <- get_auth("your.email@example.com", agree = TRUE)
8282
#' # Then ask for a sample download
8383
#' download_sample("SCPCS000001", auth_token, destination = "scpca_data", format = "sce")
8484
#'
@@ -105,7 +105,7 @@ download_sample <- function(
105105
if (!dir.exists(destination)) {
106106
dir.create(destination, recursive = TRUE)
107107
}
108-
sample_info <- get_sample_info(sample_id)
108+
sample_info <- get_sample_info(sample_id, simplifyVector = FALSE)
109109

110110
file_ids <- get_computed_file_ids(sample_info, filters = computed_files_filter(format_str))
111111

@@ -175,7 +175,7 @@ download_sample <- function(
175175
#'
176176
#' \dontrun{
177177
#' # Get a token first
178-
#' auth_token <- get_auth("me@email.net", agree = TRUE)
178+
#' auth_token <- get_auth("your.email@example.com", agree = TRUE)
179179
#' # Then ask for a sample download
180180
#' download_project("SCPCS000001", auth_token, destination = "scpca_data", format = "sce")
181181
#'
@@ -218,7 +218,7 @@ download_project <- function(
218218
dir.create(destination, recursive = TRUE)
219219
}
220220

221-
project_info <- get_project_info(project_id)
221+
project_info <- get_project_info(project_id, simplifyVector = FALSE)
222222

223223
# default to include multiplexed for SCE, not for others (where they are not available)
224224
if (is.null(include_multiplexed)) {
@@ -289,8 +289,8 @@ download_and_extract_file <- function(url, parent_dir, overwrite, redownload, qu
289289
"Directory {destination_dir} already exists; skipping download.",
290290
"\nUse 'overwrite = TRUE' to replace existing files."
291291
))
292-
# no files downloaded, return empty vector
293-
return(c())
292+
# return contents of the existing directory
293+
return(list.files(destination_dir, full.names = TRUE, recursive = TRUE))
294294
}
295295

296296
# check for existing directory with same base name (without date)

R/projects.R

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#' @param simplify A logical indicating whether to simplify the resulting data frame
1111
#' by removing list columns. Default is TRUE.
1212
#'
13-
#' @returns a data frame of project information from the ScPCA API.
13+
#' @returns a data frame (tibble) of project information from the ScPCA API.
1414
#'
1515
#' @import httr2
1616
#' @importFrom dplyr .data
@@ -47,17 +47,22 @@ scpca_projects <- function(simplify = TRUE) {
4747
created_at = as.POSIXct(.data$created_at),
4848
updated_at = as.POSIXct(.data$updated_at)
4949
) |>
50-
dplyr::relocate(scpca_project_id = "scpca_id")
50+
dplyr::relocate(
51+
scpca_project_id = "scpca_id",
52+
"sample_count",
53+
"title",
54+
"pi_name"
55+
)
5156

52-
project_df
57+
tibble::as_tibble(project_df)
5358
}
5459

5560
#' Get project metadata by project ID
5661
#'
5762
#' @param project_id The ScPCA project ID (e.g. "SCPCP000001")
5863
#' @param simplifyVector Simplify the returned list structure,
5964
#' creating vectors and data frames instead of lists when possible.
60-
#' Default is FALSE.
65+
#' Default is TRUE.
6166
#'
6267
#' @returns A nested list of project metadata from the ScPCA API.
6368
#'
@@ -69,7 +74,7 @@ scpca_projects <- function(simplify = TRUE) {
6974
#' # Get metadata for a specific project
7075
#' project_info <- get_project_info("SCPCP000001")
7176
#' }
72-
get_project_info <- function(project_id, simplifyVector = FALSE) {
77+
get_project_info <- function(project_id, simplifyVector = TRUE) {
7378
stopifnot(
7479
"Invalid project_id." = grepl("^SCPCP\\d{6}$", project_id)
7580
)
@@ -102,7 +107,7 @@ get_project_info <- function(project_id, simplifyVector = FALSE) {
102107
#' @param simplify A logical indicating whether to simplify the resulting data frame
103108
#' by removing list columns. Default is TRUE.
104109
#'
105-
#' @returns A data frame of sample information for the specified project from the ScPCA API.
110+
#' @returns A data frame (tibble) of sample information for the specified project from the ScPCA API.
106111
#'
107112
#' @import httr2
108113
#' @importFrom dplyr .data
@@ -137,9 +142,12 @@ get_project_samples <- function(project_id, simplify = TRUE) {
137142
created_at = as.POSIXct(.data$created_at),
138143
updated_at = as.POSIXct(.data$updated_at)
139144
) |>
140-
dplyr::relocate(scpca_sample_id = "scpca_id", scpca_project_id = "project")
145+
dplyr::relocate(
146+
scpca_sample_id = "scpca_id",
147+
scpca_project_id = "project"
148+
)
141149

142-
sample_df
150+
tibble::as_tibble(sample_df)
143151
}
144152

145153

@@ -200,7 +208,7 @@ get_project_libraries <- function(project_id, auth_token) {
200208
is_cols <- stringr::str_subset(colnames(library_metadata), "^(is|has|includes)_")
201209
library_metadata <- library_metadata |>
202210
dplyr::mutate(dplyr::across(dplyr::all_of(is_cols), as.logical))
203-
library_metadata
211+
tibble::as_tibble(library_metadata)
204212
}
205213

206214

R/samples.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#' @param sample_id The ScPCA sample ID (e.g. "SCPCS000001")
44
#' @param simplifyVector Simplify the returned list structure,
55
#' creating vectors and data frames instead of lists when possible.
6-
#' Default is FALSE.
6+
#' Default is TRUE.
77
#'
88
#' @returns A nested list of sample metadata from the ScPCA API.
99
#'
@@ -15,7 +15,7 @@
1515
#' # Get metadata for a specific sample
1616
#' sample_info <- get_sample_info("SCPCS000001")
1717
#' }
18-
get_sample_info <- function(sample_id, simplifyVector = FALSE) {
18+
get_sample_info <- function(sample_id, simplifyVector = TRUE) {
1919
stopifnot(
2020
"Invalid sample_id" = grepl("^SCPCS\\d{6}$", sample_id)
2121
)

ScPCAr.Rproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ SaveWorkspace: No
55
AlwaysSaveHistory: Default
66

77
EnableCodeIndexing: Yes
8+
UseSpacesForTab: Yes
9+
NumSpacesForTab: 2
810
Encoding: UTF-8
911

12+
RnwWeave: Sweave
13+
LaTeX: pdfLaTeX
14+
1015
AutoAppendNewline: Yes
1116
StripTrailingWhitespace: Yes
1217
LineEndingConversion: Posix

0 commit comments

Comments
 (0)