Skip to content

Commit

Permalink
first draft of the package
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Jan 8, 2024
1 parent d9a7f26 commit 0b24c18
Show file tree
Hide file tree
Showing 22 changed files with 397 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
^LICENSE\.md$
^_pkgdown\.yml$
^docs$
^pkgdown$
^README\.Rmd$
^\.github$
^Makefile$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs
17 changes: 17 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Package: proofr
Title: Client for the PROOF API
Version: 0.0.0.91
Authors@R:
person("Scott", "Chamberlain", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-1444-9135"))
Description: Client for the PROOF API.
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Imports:
httr
Suggests:
testthat (>= 3.0.0),
withr
Config/testthat/edition: 3
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
PACKAGE := $(shell grep '^Package:' DESCRIPTION | sed -E 's/^Package:[[:space:]]+//')
RSCRIPT = Rscript --no-init-file
FILE_TARGET := "R/${FILE}.R"

install: doc build
R CMD INSTALL . && rm *.tar.gz

build:
R CMD build .

doc:
${RSCRIPT} -e "devtools::document()"

eg:
${RSCRIPT} -e "devtools::run_examples(run_dontrun = TRUE)"

check: build
_R_CHECK_CRAN_INCOMING_=FALSE R CMD CHECK --as-cran --no-manual `ls -1tr ${PACKAGE}*gz | tail -n1`
@rm -f `ls -1tr ${PACKAGE}*gz | tail -n1`
@rm -rf ${PACKAGE}.Rcheck

vign_getting_started:
cd vignettes;\
${RSCRIPT} -e "Sys.setenv(NOT_CRAN='true'); knitr::knit('${PACKAGE}.Rmd.og', output = '${PACKAGE}.Rmd')";\
cd ..

test:
${RSCRIPT} -e "devtools::test()"

readme:
${RSCRIPT} -e "knitr::knit('README.Rmd')"

lint_package:
${RSCRIPT} -e "lintr::lint_package()"

# use: `make style_file FILE=stuff.R`
# ("R/" is prepended); accepts 1 file only
style_file:
${RSCRIPT} -e 'styler::style_file(${FILE_TARGET})'

style_package:
${RSCRIPT} -e "styler::style_pkg()"
12 changes: 12 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Generated by roxygen2: do not edit by hand

export(proof_authenticate)
export(proof_job_cancel)
export(proof_job_start)
export(proof_job_status)
importFrom(httr,DELETE)
importFrom(httr,GET)
importFrom(httr,POST)
importFrom(httr,add_headers)
importFrom(httr,content)
importFrom(httr,stop_for_status)
47 changes: 47 additions & 0 deletions R/auth.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
find_token <- function(token = NULL) {
if (!is.null(token)) {
return(token)
}
token <- Sys.getenv("PROOF_TOKEN")
if (identical(token, "")) {
stop("token not found - see ?proof_authenticate")
}
token
}

#' Get header for PROOF API calls
#'
#' Utility method to get header for PROOF API calls
#'
#' @keywords internal
#' @param token PROOF API token
#' @return A `request` S3 class with the HTTP header that can be passed
#' to `httr::GET()`, `httr::POST()`, etc.
proof_header <- function(token = NULL) {
add_headers(Authorization = paste0("Bearer ", find_token(token)))
}

#' Authenticate with PROOF API
#'
#' Authenticates with HutchNet credentials, returns PROOF API token
#'
#' @export
#' @param username (character) HutchNet username
#' @param password (character) HutchNet password
#' @return A single token (character) for bearer authentication with
#' the PROOF API
#' @examples
#' # Sys.getenv("PROOF_TOKEN")
#' # x <- proof_authenticate()
#' # Sys.getenv("PROOF_TOKEN")
proof_authenticate <- function(username, password) {
response <- POST(make_url("authenticate"), body = list(
username = username,
password = password
), encode = "json")
stop_for_status(response)
parsed <- content(response, as = "parsed")
token <- parsed$token
Sys.setenv(PROOF_TOKEN = token)
token
}
14 changes: 14 additions & 0 deletions R/cancel.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#' Delete PROOF Cromwell server
#'
#' @export
#' @references <https://github.com/FredHutch/proof-api#delete-cromwell-server>
#' @details Does not return PROOF/Cromwell server URL, for that you have to
#' periodically call [proof_job_status()], or wait for the email from the
#' PROOF API
#' @return A list with fields `job_id` and `info`
proof_job_cancel <- function() {
response <- DELETE(make_url("cromwell-server"), proof_header())
# FIXME: better error handling - surface error messages
stop_for_status(response)
content(response, as = "parsed")
}
13 changes: 13 additions & 0 deletions R/job_status.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#' Get PROOF API job status - is job running, what's its URL...
#'
#' @export
#' @references <https://github.com/FredHutch/proof-api#get-cromwell-server>
#' @return A list with slots:
#' - `canJobStart`
#' - `jobStatus`
#' - `cromwellUrl`
proof_job_status <- function() {
response <- GET(make_url("cromwell-server"), proof_header())
stop_for_status(response)
content(response, as = "parsed")
}
7 changes: 7 additions & 0 deletions R/proofr-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @keywords internal
"_PACKAGE"

## usethis namespace: start
#' @importFrom httr GET POST DELETE add_headers content stop_for_status
## usethis namespace: end
NULL
21 changes: 21 additions & 0 deletions R/start.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#' Start PROOF Cromwell server
#'
#' @export
#' @param pi_name (character) PI name in the form last_f; only needed if user
#' is in more than one SLURM account
#' @references <https://github.com/FredHutch/proof-api#post-cromwell-server>
#' @details Does not return PROOF/Cromwell server URL, for that you have to
#' periodically call [proof_job_status()], or wait for the email from the
#' PROOF API
#' @return A list with fields `job_id` and `info`
proof_job_start <- function(pi_name = NULL) {
response <- POST(
make_url("cromwell-server"),
proof_header(),
body = list(pi_name = pi_name),
encode = "json"
)
# FIXME: better error handling - surface error messages
stop_for_status(response)
content(response, as = "parsed")
}
5 changes: 5 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
proof_base <- "https://proof-api.fredhutch.org"

make_url <- function(...) {
file.path(proof_base, ...)
}
34 changes: 34 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r include=FALSE}
knitr::opts_chunk$set(
comment = "#>",
collapse = TRUE,
warning = FALSE,
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# proofr

<!-- badges: start -->
[![Project Status: Concept – Not useable, no support, not open to feedback, unstable API.](https://getwilds.github.io/badges/badges/concept.svg)](https://getwilds.github.io/badges/#concept)
[![R-CMD-check](https://github.com/getwilds/proofr/actions/workflows/R-CMD-check.yaml/badge.svg?branch=dev)](https://github.com/getwilds/proofr/actions/workflows/R-CMD-check.yaml)
[![R-CMD-check](https://github.com/getwilds/proofr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/getwilds/proofr/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

R client for the PROOF API

PROOF API is at <https://github.com/FredHutch/proof-api>



## Installation

You can install the development version of proofr from [GitHub](https://github.com/) with:

```r
# install.packages("pak")
pak::pak("getwilds/proofr")
```
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!-- README.md is generated from README.Rmd. Please edit that file -->



# proofr

<!-- badges: start -->
[![Project Status: Concept – Not useable, no support, not open to feedback, unstable API.](https://getwilds.github.io/badges/badges/concept.svg)](https://getwilds.github.io/badges/#concept)
[![R-CMD-check](https://github.com/getwilds/proofr/actions/workflows/R-CMD-check.yaml/badge.svg?branch=dev)](https://github.com/getwilds/proofr/actions/workflows/R-CMD-check.yaml)
[![R-CMD-check](https://github.com/getwilds/proofr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/getwilds/proofr/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

R client for the PROOF API

PROOF API is at <https://github.com/FredHutch/proof-api>



## Installation

You can install the development version of proofr from [GitHub](https://github.com/) with:

```r
# install.packages("pak")
pak::pak("getwilds/proofr")
```
4 changes: 4 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
url: ~
template:
bootstrap: 5

25 changes: 25 additions & 0 deletions man/proof_authenticate.Rd

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

19 changes: 19 additions & 0 deletions man/proof_header.Rd

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

22 changes: 22 additions & 0 deletions man/proof_job_cancel.Rd

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

26 changes: 26 additions & 0 deletions man/proof_job_start.Rd

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

22 changes: 22 additions & 0 deletions man/proof_job_status.Rd

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

15 changes: 15 additions & 0 deletions man/proofr-package.Rd

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

Loading

0 comments on commit 0b24c18

Please sign in to comment.