Skip to content

Commit

Permalink
Merge pull request #177 from ropensci/T171_donttest
Browse files Browse the repository at this point in the history
Changed examples from dontrun to using examplesif so that they do not run on cran
  • Loading branch information
jooolia authored Nov 24, 2023
2 parents 243b2bf + c4d327a commit 5f38712
Show file tree
Hide file tree
Showing 22 changed files with 51 additions and 88 deletions.
3 changes: 1 addition & 2 deletions R/allgensnp.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
#' @param usersubset Get a subset of users, integer numbers, e.g. 1-8 (default: none)
#' @param ... Curl options passed on to [crul::HttpClient]
#' @return data.frame of genotypes for all users at a certain SNP
#' @examples \dontrun{
#' @examplesIf !rsnps:::is_rcmd_check()
#' x <- allgensnp(snp = "rs7412")
#' head(x)
#' }
allgensnp <- function(snp = NA, usersubset = FALSE, ...) {
## add possibilty to get a subset of users

Expand Down
8 changes: 2 additions & 6 deletions R/allphenotypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@
#' number_of_users are replicated in the data.frame. Default: `FALSE`
#' @param ... Curl options passed on to [crul::HttpClient]
#' @return data.frame of openSNP phenotypes, variants and users per phenotype, or list if `df=FALSE`
#' @examples \dontrun{
#' # Get all data
#' allphenotypes(df = TRUE)
#'
#' @examplesIf !rsnps:::is_rcmd_check()
#' # Output a list, then call the characteristic of interest by 'id' or
#' # 'characteristic'
#' 'characteristic'
#' datalist <- allphenotypes()
#' names(datalist) # get list of all characteristics you can call
#' datalist[["ADHD"]] # get data.frame for 'ADHD'
#' datalist[c("mouth size", "SAT Writing")] # get data.frame for 'ADHD'
#' }
allphenotypes <- function(df = FALSE, ...) {
tryCatch(
{
Expand Down
4 changes: 2 additions & 2 deletions R/annotations.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' metadata for the response.
#' @param ... Curl options passed on to [crul::HttpClient]
#' @return data.frame of openSNP phenotypes from specified source
#' @examples \dontrun{
#' @examplesIf !rsnps:::is_rcmd_check()
#' # Get all data
#' ## get just the metadata
#' annotations(snp = "rs7903146", output = "metadata")
Expand All @@ -26,7 +26,7 @@
#'
#' ## get all annotations
#' annotations(snp = "rs7903146", output = "all")
#' }

annotations <- function(snp = NA,
output = c("all", "plos", "mendeley", "snpedia", "metadata"), ...) {
url <- paste0(osnp_base(), "snps/json/annotation/", snp, ".json")
Expand Down
15 changes: 6 additions & 9 deletions R/download_users.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@
#' @param ... Curl options passed on to [crul::HttpClient]
#' @return File downloaded to directory you specify (or default), nothing
#' returned in R.
#' @examples \dontrun{
#' @examplesIf !rsnps:::is_rcmd_check()
#' # Download a single user file, by id
#' download_users(id = 14)
#'
#' # Download a single user file, by user name
#' download_users(name = "kevinmcc")
#'
#' # Download many user files
#' lapply(c(14, 22), function(x) download_users(id = x))
#' read_users(id = 14, nrows = 5)
#' }

download_users <- function(name = NULL, id = NULL, dir = "~/", ...) {
if (is.null(name) && is.null(id)) {
stop("You must specify one of name or id", call. = FALSE)
Expand Down Expand Up @@ -65,11 +61,12 @@ get_write <- function(x, y, ...) {
#' variables for the path to the file saved. Alternatively, you can supply
#' the path.
#' @return A data.frame with openSNP user files retrieved from local storage
#' @examples \dontrun{
#' @examplesIf !rsnps:::is_rcmd_check()
#'
#' download_users(name = "kevinmcc")
#' dat <- read_users(name = "kevinmcc")
#' head(dat)
#' dat <- read_users(id = 285)
#' }

read_users <- function(name = NULL, id = NULL, path = NULL, ...) {
if (is.null(name) && is.null(id) && is.null(path)) {
stop("You must specify one of name, id, or path", call. = FALSE)
Expand Down
4 changes: 1 addition & 3 deletions R/fetch_genotypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@
#' Internally, we use [download.file()] to download each file, then
#' [read.table()] to read the file to a data.frame.
#'
#' @examples \dontrun{
#' @examplesIf !rsnps:::is_rcmd_check()
#' # get a data.frame of the users data
#' data <- users(df = TRUE)
#' head(data[[1]]) # users with links to genome data
#' mydata <- fetch_genotypes(
#' url = data[[1]][1, "genotypes.download_url"],
#' file = "~/myfile.txt"
Expand All @@ -42,7 +41,6 @@
#'
#' # Or read in data later separately
#' read.table("~/myfile.txt", nrows = 10)
#' }
fetch_genotypes <- function(url, rows = 100, filepath = NULL, quiet = TRUE, ...) {
if (is.null(filepath)) filepath <- tempfile(fileext = ".txt")

Expand Down
3 changes: 1 addition & 2 deletions R/genotypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
#' @param ... Curl options passed on to [crul::HttpClient]]
#' @return List (or data.frame) of genotypes for specified user(s) at a
#' certain SNP.
#' @examples \dontrun{
#' @examplesIf !rsnps:::is_rcmd_check()
#' genotypes(snp = "rs9939609", userid = 1)
#' genotypes("rs9939609", userid = "1,6,8", df = TRUE)
#' genotypes("rs9939609", userid = "1-2", df = FALSE)
#' }
genotypes <- function(snp = NA, userid = NA, df = FALSE, ...) {
url2 <- paste0(paste0(osnp_base(), "snps/json/"), snp, "/", userid, ".json")

Expand Down
6 changes: 2 additions & 4 deletions R/ncbi_snp_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -211,23 +211,21 @@ get_gene_names <- function(primary_info) {
#' If users want to set curl options when querying for the SNPs they can do so by using
#' httr::set_config/httr::with_config
#'
#' @examples \dontrun{
#' @examplesIf !rsnps:::is_rcmd_check()
#' ## an example with both merged SNPs, non-SNV SNPs, regular SNPs,
#' ## SNPs not found, microsatellite
#' SNPs <- c("rs332", "rs420358", "rs1837253", "rs1209415715", "rs111068718")
#' ncbi_snp_query(SNPs)
#' # ncbi_snp_query("123456") ##invalid: must prefix with 'rs'
#' ncbi_snp_query("rs420358")
#' ncbi_snp_query("rs332") # warning that its merged into another, try that
#' ncbi_snp_query("rs332") # warning that its merged into another
#' ncbi_snp_query("rs121909001")
#' ncbi_snp_query("rs1837253")
#' ncbi_snp_query("rs1209415715")
#' ncbi_snp_query("rs111068718")
#' ncbi_snp_query(snps = "rs9970807")
#'
#' ncbi_snp_query("rs121909001")
#' ncbi_snp_query("rs121909001", verbose = TRUE)
#' }
ncbi_snp_query <- function(snps) {

## NCBI moved to https but not using http v.2. The setting of the version
Expand Down
9 changes: 1 addition & 8 deletions R/phenotypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,13 @@
#' @param ... Curl options passed on to [crul::HttpClient]
#' @return List of phenotypes for specified user(s) from openSNP.
#'
#' @examples \dontrun{
#' @examplesIf !rsnps:::is_rcmd_check()
#' phenotypes(userid = 1)
#' phenotypes(userid = "1,6,8", df = TRUE)
#' phenotypes(userid = "1-8", df = TRUE)
#'
#' # coerce to data.frame
#' library(plyr)
#' df <- ldply(phenotypes(userid = "1-8", df = TRUE))
#' head(df)
#' tail(df)
#'
#' # pass on curl options
#' phenotypes(1, verbose = TRUE)
#' }
phenotypes <- function(userid = NA, df = FALSE, ...) {
url2 <- paste0(paste0(osnp_base(), "phenotypes/json/"), userid, ".json")

Expand Down
4 changes: 1 addition & 3 deletions R/phenotypes_byid.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
#' @param ... Curl options passed on to [crul::HttpClient]
#' @return List of description of phenotype, list of known variants, or
#' data.frame of variants for each user with that phenotype retrieved from openSNP.
#'
#' @examples \dontrun{
#' @examplesIf !rsnps:::is_rcmd_check()
#' phenotypes_byid(phenotypeid = 12, return_ = "desc")
#' phenotypes_byid(phenotypeid = 12, return_ = "knownvars")
#' phenotypes_byid(phenotypeid = 12, return_ = "users")
#'
#' # pass on curl options
#' phenotypes_byid(phenotypeid = 12, return_ = "desc", verbose = TRUE)
#' }
phenotypes_byid <- function(phenotypeid = NA,
return_ = c("description", "knownvars", "users"), ...) {
url2 <- paste0(
Expand Down
7 changes: 1 addition & 6 deletions R/users.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
#' @param df Return data.frame (`TRUE`) or not (`FALSE`). Default: `FALSE`
#' @param ... Curl options passed on to [crul::HttpClient]
#' @return List of openSNP users, their ID numbers, and genome data if available.
#' @examples \dontrun{
#' # just the list
#' data <- users(df = FALSE)
#' data
#'
#' @examplesIf !rsnps:::is_rcmd_check()
#' # get a data.frame of the users data
#' data <- users(df = TRUE)
#' data[[1]] # users with links to genome data
#' data[[2]] # users without links to genome data
#' }
users <- function(df = FALSE, ...) {


Expand Down
8 changes: 8 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,11 @@ release_bullets <- function() {
"Bump dev version"
)
}

is_rcmd_check <- function () {
if (identical(Sys.getenv("NOT_CRAN"), "true")) {
FALSE
} else {
Sys.getenv("_R_CHECK_PACKAGE_NAME_", "") != ""
}
}
4 changes: 2 additions & 2 deletions man/allgensnp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions man/allphenotypes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/annotations.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions man/download_users.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions man/fetch_genotypes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/genotypes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/ncbi_snp_query.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions man/phenotypes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/phenotypes_byid.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5f38712

Please sign in to comment.