Skip to content

Commit

Permalink
Merge pull request #173 from ropensci/patch_T171
Browse files Browse the repository at this point in the history
Patch t171
  • Loading branch information
jooolia authored Jun 30, 2023
2 parents 4492c07 + 8e15e4c commit cd3eb5d
Show file tree
Hide file tree
Showing 20 changed files with 2,952 additions and 75 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ revdep
^pkgdown$
^codecov\.yml$
^revdep$
^CRAN-SUBMISSION$
20 changes: 19 additions & 1 deletion R/allgensnp.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,25 @@ allgensnp <- function(snp = NA, usersubset = FALSE, ...) {
}else{
url2 <- paste(osnp_base(), "snps/", snp, ".json", sep = "")
}
out <- os_GET(url2, list(), ...)

tryCatch(
{
out <- os_GET(url2, list(), ...)
## need to check what it returns
# Process the data or perform any desired operations
},
error = function(e) {
message("Failed to retrieve data from OpenSNP. Please check the URL or try again later.")
stop("Error - Failed to retrieve data from OpenSNP or connection is interrupted")
}
,
warning = function(w) {
message("Warning: Data retrieval resulted in a warning.")
# Handle warnings if necessary
stop("Warning - Failed to retrieve data from OpenSNP or connection is interrupted")
}
)

tt <- jsonlite::fromJSON(out, FALSE)
rbl(lapply(tt, function(z) {
snp <- data.frame(z$snp, stringsAsFactors = FALSE)
Expand Down
19 changes: 18 additions & 1 deletion R/allphenotypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,24 @@
#' datalist[c("mouth size", "SAT Writing")] # get data.frame for 'ADHD'
#' }
allphenotypes <- function(df = FALSE, ...) {
out <- os_GET(paste0(osnp_base(), "phenotypes.json"), list(), ...)
tryCatch(
{
out <- os_GET(paste0(osnp_base(), "phenotypes.json"), list(), ...)
## need to check what it returns
# Process the data or perform any desired operations
},
error = function(e) {
message("Failed to retrieve data from OpenSNP. Please check the URL or try again later.")
stop("Error - Failed to retrieve data from OpenSNP or connection is interrupted")
}
,
warning = function(w) {
message("Warning: Data retrieval resulted in a warning.")
# Handle warnings if necessary
stop("Warning - Failed to retrieve data from OpenSNP or connection is interrupted")
}
)

out <- jsonlite::fromJSON(out, simplifyVector = FALSE)
if (df) {
ldply(out, function(x) {
Expand Down
20 changes: 19 additions & 1 deletion R/annotations.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,25 @@
annotations <- function(snp = NA,
output = c("all", "plos", "mendeley", "snpedia", "metadata"), ...) {
url <- paste0(osnp_base(), "snps/json/annotation/", snp, ".json")
out <- os_GET(url, list(), ...)

tryCatch(
{
out <- os_GET(url, list(), ...)
## need to check what it returns
# Process the data or perform any desired operations
},
error = function(e) {
message("Failed to retrieve data from OpenSNP. Please check the URL or try again later.")
stop("Error - Failed to retrieve data from OpenSNP or connection is interrupted")
}
,
warning = function(w) {
message("Warning: Data retrieval resulted in a warning.")
# Handle warnings if necessary
stop("Warning - Failed to retrieve data from OpenSNP or connection is interrupted")
}
)

out <- jsonlite::fromJSON(out, FALSE)
source_ <- match.arg(
output, c("all", "plos", "mendeley", "snpedia", "metadata"),
Expand Down
21 changes: 18 additions & 3 deletions R/fetch_genotypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,25 @@
#' }
fetch_genotypes <- function(url, rows = 100, filepath = NULL, quiet = TRUE, ...) {
if (is.null(filepath)) filepath <- tempfile(fileext = ".txt")
utils::download.file(url, destfile = filepath, quiet = quiet, ...)

tryCatch(
{
utils::download.file(url, destfile = filepath, quiet = quiet, ...)
},
error = function(e) {
message("Failed to retrieve data. Please check the URL or try again later.")
stop("No URL available")
}
,
warning = function(w) {
message("Warning: Data retrieval resulted in a warning.")
# Handle warnings if necessary
return(NULL)
}
)
df <- utils::read.table(filepath,
sep = "\t", nrows = rows, header = FALSE,
comment.char = "#", stringsAsFactors = FALSE
sep = "\t", nrows = rows, header = FALSE,
comment.char = "#", stringsAsFactors = FALSE
)
stats::setNames(df, c("rsid", "chromosome", "position", "genotype"))
}
19 changes: 18 additions & 1 deletion R/genotypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,24 @@
#' }
genotypes <- function(snp = NA, userid = NA, df = FALSE, ...) {
url2 <- paste0(paste0(osnp_base(), "snps/json/"), snp, "/", userid, ".json")
res <- os_GET(url2, list(), ...)

tryCatch(
{
res <- os_GET(url2, list(), ...)
## need to check what it returns
# Process the data or perform any desired operations
},
error = function(e) {
message("Failed to retrieve data from OpenSNP. Please check the URL or try again later.")
stop("Error - Failed to retrieve data from OpenSNP or connection is interrupted")
}
,
warning = function(w) {
message("Warning: Data retrieval resulted in a warning.")
# Handle warnings if necessary
stop("Warning - Failed to retrieve data from OpenSNP or connection is interrupted")
}
)
genotypes_ <- jsonlite::fromJSON(res, FALSE)

if (df) {
Expand Down
19 changes: 18 additions & 1 deletion R/phenotypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,24 @@
#' }
phenotypes <- function(userid = NA, df = FALSE, ...) {
url2 <- paste0(paste0(osnp_base(), "phenotypes/json/"), userid, ".json")
res <- os_GET(url2, list(), ...)

tryCatch(
{
res <- os_GET(url2, list(), ...)
## need to check what it returns
# Process the data or perform any desired operations
},
error = function(e) {
message("Failed to retrieve data from OpenSNP. Please check the URL or try again later.")
stop("Error - Failed to retrieve data from OpenSNP or connection is interrupted")
}
,
warning = function(w) {
message("Warning: Data retrieval resulted in a warning.")
# Handle warnings if necessary
stop("Warning - Failed to retrieve data from OpenSNP or connection is interrupted")
}
)
out <- jsonlite::fromJSON(res, FALSE)

userid <- gsub("-", ",", userid)
Expand Down
20 changes: 19 additions & 1 deletion R/phenotypes_byid.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,25 @@ phenotypes_byid <- function(phenotypeid = NA,
paste0(osnp_base(), "phenotypes/json/variations/"),
phenotypeid, ".json"
)
res <- os_GET(url2, list(), ...)

tryCatch(
{
res <- os_GET(url2, list(), ...)
## need to check what it returns
# Process the data or perform any desired operations
},
error = function(e) {
message("Failed to retrieve data from OpenSNP. Please check the URL or try again later.")
stop("Error - Failed to retrieve data from OpenSNP or connection is interrupted")
}
,
warning = function(w) {
message("Warning: Data retrieval resulted in a warning.")
# Handle warnings if necessary
stop("Warning - Failed to retrieve data from OpenSNP or connection is interrupted")
}
)

out <- jsonlite::fromJSON(res, FALSE)

return_2 <- match.arg(return_, c("description", "knownvars", "users"), FALSE)
Expand Down
21 changes: 20 additions & 1 deletion R/users.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,26 @@
#' data[[2]] # users without links to genome data
#' }
users <- function(df = FALSE, ...) {
res <- os_GET(paste0(osnp_base(), "users.json"), list(), ...)


tryCatch(
{
res <- os_GET(paste0(osnp_base(), "users.json"), list(), ...)
## need to check what it returns
# Process the data or perform any desired operations
},
error = function(e) {
message("Failed to retrieve data from OpenSNP. Please check the URL or try again later.")
stop("Error - Failed to retrieve data from OpenSNP or connection is interrupted")
}
,
warning = function(w) {
message("Warning: Data retrieval resulted in a warning.")
# Handle warnings if necessary
stop("Warning - Failed to retrieve data from OpenSNP or connection is interrupted")
}
)

users_ <- jsonlite::fromJSON(res, FALSE)
if (!df) {
users_
Expand Down
13 changes: 12 additions & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,20 @@ We checked 1 reverse dependencies (0 from CRAN + 1 from Bioconductor), comparing
* We saw 0 new problems
* We failed to check 0 packages


4. A fourth note is related to the resubmission of the update following some failing tests on CRAN

```
* checking CRAN incoming feasibility ... [10s] NOTE
Maintainer: 'Julia Gustavsen <[email protected]>'
Days since last update: 4
```

---

This version includes more tests, some spelling corrections and some formatting corrections.
This version includes more tests, fixes and catches for failing tests,some spelling corrections and some formatting corrections.


Thanks!
Expand Down
49 changes: 49 additions & 0 deletions tests/fixtures/allgensnp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
http_interactions:
- request:
method: get
uri: https://opensnp.org/snps/json/rs486907/1-8.json
body:
encoding: ''
string: ''
headers:
User-Agent: libcurl/7.64.1 r-curl/5.0.1 crul/1.4.0
Accept-Encoding: gzip, deflate
Accept: application/json, text/xml, application/xml, */*
response:
status:
status_code: '200'
message: OK
explanation: Request fulfilled, document follows
headers:
cache-control: max-age=0, private, must-revalidate
connection: keep-alive
content-encoding: gzip
content-type: application/json; charset=utf-8
date: Fri, 30 Jun 2023 09:53:59 GMT
etag: W/"171b5a10145cfdc824a295229d993078"
server: nginx/1.18.0 + Phusion Passenger(R) 6.0.17
status:
- HTTP/1.1 200 OK
- 200 OK
strict-transport-security: max-age=31536000; includeSubDomains
transfer-encoding: chunked
vary: Accept-Encoding
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-powered-by: Phusion Passenger(R) 6.0.17
x-request-id: a2956f8d-9ec9-48ba-80bc-0426929b90b0
x-runtime: '0.446335'
x-xss-protection: 1; mode=block
body:
encoding: ''
file: no
string: '[{"snp":{"name":"rs486907","chromosome":"1","position":"182585422"},"user":{"name":"Bastian
Greshake Tzovaras","id":1,"genotypes":[{"genotype_id":9,"local_genotype":"TT"}]}},{"snp":{"name":"rs486907","chromosome":"1","position":"182585422"},"user":{"name":"Senficon","id":2,"genotypes":[]}},{"error":"Sorry,
we couldn''t find any information for SNP rs486907 and user 3"},{"error":"Sorry,
we couldn''t find any information for SNP rs486907 and user 4"},{"error":"Sorry,
we couldn''t find any information for SNP rs486907 and user 5"},{"snp":{"name":"rs486907","chromosome":"1","position":"182585422"},"user":{"name":"Nash
Parovoz","id":6,"genotypes":[{"genotype_id":5,"local_genotype":"CC"}]}},{"error":"Sorry,
we couldn''t find any information for SNP rs486907 and user 7"},{"snp":{"name":"rs486907","chromosome":"1","position":"182585422"},"user":{"name":"Samantha
B. Clark","id":8,"genotypes":[{"genotype_id":2,"local_genotype":"TT"}]}}]'
recorded_at: 2023-06-30 09:53:59 GMT
recorded_with: vcr/1.2.0, webmockr/0.9.0
47 changes: 47 additions & 0 deletions tests/fixtures/allgensnp_error.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
http_interactions:
- request:
method: get
uri: https://opensnp.org/snps/json/rs486907/1-8.json
body:
encoding: ''
string: ''
headers:
User-Agent: libcurl/7.64.1 r-curl/5.0.1 crul/1.4.0
Accept-Encoding: gzip, deflate
Accept: application/json, text/xml, application/xml, */*
response:
status:
status_code: '503'
message: Service Unavailable
explanation: The server cannot process the request due to a high load
headers:
status: HTTP/1.1 503 Service Temporarily Unavailable
server: nginx/1.18.0 (Ubuntu)
date: Fri, 30 Jun 2023 09:40:20 GMT
content-type: text/html
content-length: '307'
connection: keep-alive
etag: '"6467496a-133"'
body:
encoding: ''
file: no
string: |
<!DOCTYPE html>
<html>
<head>
<title>OpenSNP is down for maintenance</title>
</head>
<body>
<style>
h1 {
color:#0069d6;
}
</style>
<center>
<h1>openSNP</h1>
<h3>We are working on something. Please check again later.</h3>
</center>
</body>
</html>
recorded_at: 2023-06-30 09:40:20 GMT
recorded_with: vcr/1.2.0, webmockr/0.9.0
Loading

0 comments on commit cd3eb5d

Please sign in to comment.