Commit 83a437bc authored by jml's avatar jml
Browse files

add alapur object

parent 350ee518
Package: alapur
Type: Package
Version: 0.0.1
Version: 0.0.2
Authors@R: c(person("Jean-Marie", "Lepioufle", , "jml@nilu.no", role=c("aut","cre")),
person("NILU",role="cph"))
Title: alapur
......@@ -14,4 +14,4 @@ Imports:
License: GPL-3
Encoding: UTF-8
LazyData: false
RoxygenNote: 5.0.1
RoxygenNote: 6.0.1
......@@ -2,7 +2,7 @@
export(alapu_get)
export(alapu_post)
export(config_server)
export(alapur)
export(endpoints_alapu)
export(endpoints_package)
export(endpoints_session)
......
#' alapur
#'
#' alapur
#' @param server server IP adress
#' @keywords alapur
#' @export
#' @examples
#' \dontrun{
#' alapur()
#' }
alapur <- function(server){
alapur_object(server=server)
}
alapur_object <- function(server){
server_ <- server
object <- local({
get <- function(api,pkgname=NULL,key=NULL,epoint=NULL,object=NULL,format=NULL,filename=NULL,res_path=NULL,...){
res <- alapu_get(server=server_,api=api,pkgname=pkgname,key=key,epoint=epoint,object=object,format=format,filename=filename,res_path=res_path,...)
return(res)
}
post <- function(api,pkgname=NULL,key=NULL,epoint=NULL,object=NULL,format=NULL,filename=NULL,...){
res <- alapu_post(server=server_,api=api,pkgname=pkgname,key=key,epoint=epoint,object=object,format=format,filename=filename,...)
return(res)
}
summary <- function(){
print("alapur client api")
}
environment()
})
lockEnvironment(object, TRUE)
structure(object, class=c("alapur", class(object)))
}
#' config_server
#' config_server
#' @param url url
#' @param override override
#' @keywords alapu
#' @export
#' @examples
#' \dontrun{
#' config_server()
#' }
config_server <- function(url,override = FALSE) {
old <- try(getOption("alapu_server"))
if (inherits(old,"try-error")){
old <- NULL
}
if ((!override) && (!is.null(old))) {
config <- c(url,old)
} else config <- url
options(alapu_server = config)
invisible(old)
}
#' endpoints_alapu
#' endpoints_alapu
#' @param server server IP adress
#' @param api api endpoint
#' @param pkgname pkgname
#' @param key session key
......@@ -14,13 +15,13 @@
#' \dontrun{
#' endpoints_alapu()
#' }
endpoints_alapu <- function(api=c("package","session"),pkgname=NULL,key=NULL,epoint=NULL,object=NULL,format=NULL,filename=NULL){
endpoints_alapu <- function(server,api=c("package","session"),pkgname=NULL,key=NULL,epoint=NULL,object=NULL,format=NULL,filename=NULL){
api <- match.arg(api,c("package","session"))
res <- switch(api,
"package" = endpoints_package(pkgname=pkgname,epoint=epoint,object=object,format=format),
"session" = endpoints_session(key=key,epoint=epoint,object=object,format=format,filename=filename),
"package" = endpoints_package(server=server,pkgname=pkgname,epoint=epoint,object=object,format=format),
"session" = endpoints_session(server=server,key=key,epoint=epoint,object=object,format=format,filename=filename),
stop("endpoints not recognized"))
class(res) <- "alapu_endpoints"
......@@ -31,6 +32,7 @@ endpoints_alapu <- function(api=c("package","session"),pkgname=NULL,key=NULL,epo
#' endpoints_package
#' endpoints_package
#' @param server server IP adress
#' @param pkgname pkgname
#' @param epoint endpoint
#' @param object object
......@@ -41,7 +43,7 @@ endpoints_alapu <- function(api=c("package","session"),pkgname=NULL,key=NULL,epo
#' \dontrun{
#' endpoints_package()
#' }
endpoints_package <- function(pkgname=NULL,epoint=NULL,object=NULL,format=NULL){
endpoints_package <- function(server,pkgname=NULL,epoint=NULL,object=NULL,format=NULL){
if (is.null(pkgname) || is.null(epoint)) {
stop("argument 'pkgname' and 'epoint' required")
......@@ -58,12 +60,12 @@ endpoints_package <- function(pkgname=NULL,epoint=NULL,object=NULL,format=NULL){
}
res <- switch(epoint,
"info" = alapu_url("library",pkgname,"info"),
"www" = alapu_url("library",pkgname,"www"),
"R" = alapu_url("library",pkgname,"R",object=object,format=format),
"data" = alapu_url("library",pkgname,"data",object=object,format=format),
"man" = alapu_url("library",pkgname,"man",object=object,format=format),
"html" = alapu_url("library",pkgname,"html"),
"info" = alapu_url(server,"library",pkgname,"info"),
"www" = alapu_url(server,"library",pkgname,"www"),
"R" = alapu_url(server,"library",pkgname,"R",object=object,format=format),
"data" = alapu_url(server,"library",pkgname,"data",object=object,format=format),
"man" = alapu_url(server,"library",pkgname,"man",object=object,format=format),
"html" = alapu_url(server,"library",pkgname,"html"),
stop("epoint unknown ",epoint)
)
......@@ -75,6 +77,7 @@ endpoints_package <- function(pkgname=NULL,epoint=NULL,object=NULL,format=NULL){
#' endpoints_session
#' endpoints_session
#' @param server server IP adress
#' @param key session key
#' @param epoint endpoint
#' @param object object
......@@ -86,7 +89,7 @@ endpoints_package <- function(pkgname=NULL,epoint=NULL,object=NULL,format=NULL){
#' \dontrun{
#' endpoints_session()
#' }
endpoints_session <- function(key=NULL,epoint=NULL,object=NULL,format=NULL,filename=NULL){
endpoints_session <- function(server,key=NULL,epoint=NULL,object=NULL,format=NULL,filename=NULL){
if (is.null(key) || is.null(epoint)) {
stop("argument 'key' and 'epoint' required")
......@@ -111,15 +114,15 @@ endpoints_session <- function(key=NULL,epoint=NULL,object=NULL,format=NULL,filen
}
res <- switch(epoint,
"-" = alapu_url("tmp",key),
"R" = alapu_url("tmp",key,"R",object=object,format=format),
"graphics" = alapu_url("tmp",key,"graphics"),
"source" = alapu_url("tmp",key,"source"),
"stdout" = alapu_url("tmp",key,"stdout"),
"console" = alapu_url("tmp",key,"console"),
"zip" = alapu_url("tmp",key,"zip"),
"tar" = alapu_url("tmp",key,"tar"),
"files" = alapu_url("tmp",key,"files",filename=filename),
"-" = alapu_url(server,"tmp",key),
"R" = alapu_url(server,"tmp",key,"R",object=object,format=format),
"graphics" = alapu_url(server,"tmp",key,"graphics"),
"source" = alapu_url(server,"tmp",key,"source"),
"stdout" = alapu_url(server,"tmp",key,"stdout"),
"console" = alapu_url(server,"tmp",key,"console"),
"zip" = alapu_url(server,"tmp",key,"zip"),
"tar" = alapu_url(server,"tmp",key,"tar"),
"files" = alapu_url(server,"tmp",key,"files",filename=filename),
stop("epoint unknown ",epoint)
)
......
alapu_url <- function(...){
try(url_server <- getOption(x="alapu_server")[1])
if (inherits(url_server,"try-error")){
stop("alapu_server not defined, use config_server")
}
alapu_url <- function(server,...){
url_server <- server
param <- c(as.list(environment()), list(...))
indice <- which(unlist(lapply(param,is.null)))
if (length(indice)) {
......
#' alapu_post
#' alapu_post
#' @param server server IP adress
#' @param api api endpoint
#' @param pkgname pkgname
#' @param key session
......@@ -15,9 +16,9 @@
#' \dontrun{
#' alapu_post()
#' }
alapu_post <- function(api,pkgname=NULL,key=NULL,epoint=NULL,object=NULL,format=NULL,filename=NULL,...){
alapu_post <- function(server,api,pkgname=NULL,key=NULL,epoint=NULL,object=NULL,format=NULL,filename=NULL,...){
url <- endpoints_alapu(api=api,pkgname=pkgname,key=key,epoint=epoint,object=object,format=format,filename=filename)
url <- endpoints_alapu(server=server,api=api,pkgname=pkgname,key=key,epoint=epoint,object=object,format=format,filename=filename)
res <- httr::POST(url,body=list(...),encode = "json")
class(res) <- c("alapu_post_res",class(res))
return(res)
......@@ -26,6 +27,7 @@ alapu_post <- function(api,pkgname=NULL,key=NULL,epoint=NULL,object=NULL,format=
#' alapu_get
#' alapu_get
#' @param server server IP adress
#' @param api api endpoint
#' @param pkgname pkgname
#' @param key session
......@@ -41,9 +43,9 @@ alapu_post <- function(api,pkgname=NULL,key=NULL,epoint=NULL,object=NULL,format=
#' \dontrun{
#' alapu_get()
#' }
alapu_get <- function(api,pkgname=NULL,key=NULL,epoint=NULL,object=NULL,format=NULL,filename=NULL,res_path=NULL,...){
alapu_get <- function(server,api,pkgname=NULL,key=NULL,epoint=NULL,object=NULL,format=NULL,filename=NULL,res_path=NULL,...){
url <- endpoints_alapu(api=api,pkgname=pkgname,key=key,epoint=epoint,object=object,format=format,filename=filename)
url <- endpoints_alapu(server=server,api=api,pkgname=pkgname,key=key,epoint=epoint,object=object,format=format,filename=filename)
if (is.null(res_path)) {
res <- httr::GET(url,...)
} else if (!is.null(res_path)) {
......
......@@ -12,5 +12,4 @@ source("https://raw.githubusercontent.com/r-lib/remotes/master/install-github.R"
```R
library("remotes")
remotes::install_git("git@git.nilu.no:alapu/alapur.git")
```
# Determine package name and version from DESCRIPTION file
PKG_VERSION=$(shell grep -i ^version DESCRIPTION | cut -d : -d \ -f 2)
PKG_NAME=$(shell grep -i ^package DESCRIPTION | cut -d : -d \ -f 2)
# Name of built package
PKG_TAR=$(PKG_NAME)_$(PKG_VERSION).tar.gz
# Install package
install:
cd .. && R CMD INSTALL $(PKG_NAME)
# Build documentation with roxygen
# 1) Remove old doc
# 2) Generate documentation
roxygen:
rm -f man/*.Rd
Rscript -e "library(methods)" \
-e "library(devtools)" \
-e "devtools::document()"
# Generate PDF output from the Rd sources
# 1) Rebuild documentation with roxygen
# 2) Generate pdf, overwrites output file if it exists
pdf: roxygen
cd .. && R CMD Rd2pdf --force $(PKG_NAME)
# Build and check package
check:
cd .. && R CMD build --no-build-vignettes $(PKG_NAME)
cd .. && _R_CHECK_CRAN_INCOMING_=FALSE NOT_CRAN=true \
R CMD check --as-cran --no-manual --no-vignettes \
--no-build-vignettes --no-stop-on-test-error $(PKG_TAR)
# Check reverse dependencies
#
# 1) Install packages (in ./revdep/lib) to check reverse dependencies.
# 2) Check reverse dependencies using 'R CMD check'.
# 3) Collect results from '00check.log' files.
revdep: revdep_install revdep_check revdep_results
# Install packages to check reverse dependencies
revdep_install: clean
mkdir -p revdep/lib
cd .. && R CMD INSTALL --library=$(PKG_NAME)/revdep/lib $(PKG_NAME)
R_LIBS_USER=./revdep/lib Rscript --vanilla \
-e "options(repos = c(CRAN='https://cran.r-project.org'))" \
-e "pkg <- tools::package_dependencies('$(PKG_NAME)', which = 'all', reverse = TRUE)" \
-e "pkg <- as.character(unlist(pkg))" \
-e "dep <- sapply(pkg, tools::package_dependencies, which = 'all')" \
-e "dep <- as.character(unlist(dep))" \
-e "if ('BiocInstaller' %in% dep) {" \
-e " source('https://bioconductor.org/biocLite.R')" \
-e " biocLite('BiocInstaller')" \
-e "}" \
-e "install.packages(pkg, dependencies = TRUE)" \
-e "download.packages(pkg, destdir = 'revdep')"
# Check reverse dependencies with 'R CMD check'
revdep_check:
$(foreach var,$(wildcard revdep/*.tar.gz),R_LIBS_USER=./revdep/lib \
_R_CHECK_CRAN_INCOMING_=FALSE R --vanilla CMD check --as-cran \
--no-stop-on-test-error --output=revdep $(var) \
| tee --append revdep/00revdep.log;)
# Collect results from checking reverse dependencies
revdep_results:
Rscript --vanilla \
-e "options(repos = c(CRAN='https://cran.r-project.org'))" \
-e "pkg <- tools::package_dependencies('$(PKG_NAME)', which = 'all', reverse = TRUE)" \
-e "pkg <- as.character(unlist(pkg))" \
-e "results <- do.call('rbind', lapply(pkg, function(x) {" \
-e " filename <- paste0('revdep/', x, '.Rcheck/00check.log')" \
-e " if (file.exists(filename)) {" \
-e " lines <- readLines(filename)" \
-e " status <- sub('^Status: ', '', lines[grep('^Status: ', lines)])" \
-e " } else {" \
-e " status <- 'missing'" \
-e " }" \
-e " data.frame(Package = x, Status = status)" \
-e "}))" \
-e "results <- results[order(results[, 'Status']), ]" \
-e "rownames(results) <- NULL" \
-e "cat('\n\n*** Results ***\n\n')" \
-e "results" \
-e "cat('\n\n')"
# Build and check package with gctorture
check_gctorture:
cd .. && R CMD build --no-build-vignettes $(PKG_NAME)
cd .. && R CMD check --no-manual --no-vignettes --no-build-vignettes --use-gct $(PKG_TAR)
# Build and check package with valgrind
check_valgrind:
cd .. && R CMD build --no-build-vignettes $(PKG_NAME)
cd .. && R CMD check --as-cran --no-manual --no-vignettes --no-build-vignettes --use-valgrind $(PKG_TAR)
# Run all tests with valgrind
test_objects = $(wildcard tests/*.R)
valgrind:
$(foreach var,$(test_objects),R -d "valgrind --tool=memcheck --leak-check=full" --vanilla < $(var);)
......@@ -5,10 +5,12 @@
\title{alapu_get
alapu_get}
\usage{
alapu_get(api, pkgname = NULL, key = NULL, epoint = NULL, object = NULL,
format = NULL, filename = NULL, res_path = NULL, ...)
alapu_get(server, api, pkgname = NULL, key = NULL, epoint = NULL,
object = NULL, format = NULL, filename = NULL, res_path = NULL, ...)
}
\arguments{
\item{server}{server IP adress}
\item{api}{api endpoint}
\item{pkgname}{pkgname}
......@@ -37,4 +39,3 @@ alapu_get()
}
}
\keyword{alapu}
......@@ -5,10 +5,12 @@
\title{alapu_post
alapu_post}
\usage{
alapu_post(api, pkgname = NULL, key = NULL, epoint = NULL,
alapu_post(server, api, pkgname = NULL, key = NULL, epoint = NULL,
object = NULL, format = NULL, filename = NULL, ...)
}
\arguments{
\item{server}{server IP adress}
\item{api}{api endpoint}
\item{pkgname}{pkgname}
......@@ -35,4 +37,3 @@ alapu_post()
}
}
\keyword{alapu}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/alapur.R
\name{alapur}
\alias{alapur}
\title{alapur}
\usage{
alapur(server)
}
\arguments{
\item{server}{server IP adress}
}
\description{
alapur
}
\examples{
\dontrun{
alapur()
}
}
\keyword{alapur}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/config.R
\name{config_server}
\alias{config_server}
\title{config_server
config_server}
\usage{
config_server(url, override = FALSE)
}
\arguments{
\item{url}{url}
\item{override}{override}
}
\description{
config_server
config_server
}
\examples{
\dontrun{
config_server()
}
}
\keyword{alapu}
......@@ -5,10 +5,13 @@
\title{endpoints_alapu
endpoints_alapu}
\usage{
endpoints_alapu(api = c("package", "session"), pkgname = NULL, key = NULL,
epoint = NULL, object = NULL, format = NULL, filename = NULL)
endpoints_alapu(server, api = c("package", "session"), pkgname = NULL,
key = NULL, epoint = NULL, object = NULL, format = NULL,
filename = NULL)
}
\arguments{
\item{server}{server IP adress}
\item{api}{api endpoint}
\item{pkgname}{pkgname}
......@@ -33,4 +36,3 @@ endpoints_alapu()
}
}
\keyword{alapu}
......@@ -5,10 +5,12 @@
\title{endpoints_package
endpoints_package}
\usage{
endpoints_package(pkgname = NULL, epoint = NULL, object = NULL,
endpoints_package(server, pkgname = NULL, epoint = NULL, object = NULL,
format = NULL)
}
\arguments{
\item{server}{server IP adress}
\item{pkgname}{pkgname}
\item{epoint}{endpoint}
......@@ -27,4 +29,3 @@ endpoints_package()
}
}
\keyword{alapu}
......@@ -5,10 +5,12 @@
\title{endpoints_session
endpoints_session}
\usage{
endpoints_session(key = NULL, epoint = NULL, object = NULL,
endpoints_session(server, key = NULL, epoint = NULL, object = NULL,
format = NULL, filename = NULL)
}
\arguments{
\item{server}{server IP adress}
\item{key}{session key}
\item{epoint}{endpoint}
......@@ -29,4 +31,3 @@ endpoints_session()
}
}
\keyword{alapu}
......@@ -28,4 +28,3 @@ resp_content()
}
}
\keyword{alapu}
......@@ -20,4 +20,3 @@ resp_status()
}
}
\keyword{alapu}
......@@ -20,4 +20,3 @@ session_key()
}
}
\keyword{alapu}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment