Skip to content

Commit

Permalink
Merge pull request #165 from jread-usgs/master
Browse files Browse the repository at this point in the history
with.units for loadOutput
  • Loading branch information
Jordan S Read committed May 27, 2015
2 parents ded9622 + 37ff22c commit f016bc1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 27 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,7 +1,7 @@
Package: geoknife
Type: Package
Title: Geo-web processing of gridded data
Version: 0.10.2
Version: 0.10.3
Date: 2013-05-23
Author: Jordan S Read
Maintainer: Jordan S Read <jread@usgs.gov>
Expand Down
19 changes: 8 additions & 11 deletions R/loadOutput.R
Expand Up @@ -4,6 +4,7 @@
#'
#'@param .Object a \code{\link{geojob}} object with a successful processID.
#'(See \code{\link{check}}).
#'@param ... additional arguments passed to parsers (e.g., keep.units = TRUE)
#'@return data.frame of timeseries values.
#'@rdname loadOutput-methods
#'@aliases loadOutput
Expand All @@ -14,22 +15,18 @@
#'@export
#'@examples
#'\dontrun{
#'wp <- quick_wp()
#'job <- geoknife(stencil = c(-89,42), fabric = 'prism', knife = wp)
#'check(job)
#'
#'Sys.sleep(10) # give it some time to process
#'loadOutput(job) # load and print output
#'job <- geoknife(stencil = c(-89,42), fabric = 'prism', wait = TRUE)
#'loadOutput(job, with.units = TRUE) # load and print output
#'}
#'
setGeneric(name="loadOutput",def=function(.Object){standardGeneric("loadOutput")})
setGeneric(name="loadOutput",def=function(.Object, ...){standardGeneric("loadOutput")})

#'@rdname loadOutput-methods
#'@aliases loadOutput
setMethod(f = "loadOutput",signature="geojob",
definition = function(.Object){
definition = function(.Object, ...){
if (successful(.Object)){
output <- outputParse(.Object)
output <- outputParse(.Object, ...)
return(output)
} else {
stop('processing is incomplete or has failed. See checkProcess(). Processing status: ',
Expand All @@ -39,10 +36,10 @@ setMethod(f = "loadOutput",signature="geojob",
}
)

outputParse = function(.Object){
outputParse = function(.Object, ...){
funcInfo <- getParseFunction(id(.Object))
fileLocation <- check(.Object)$URL
output <- do.call(funcInfo$function_name, args = list(file = fileLocation, 'delim' = funcInfo$delim))
output <- do.call(funcInfo$function_name, args = list(file = fileLocation, 'delim' = funcInfo$delim, ...))
return(output)
}

Expand Down
6 changes: 3 additions & 3 deletions R/parseTimeseries.R
Expand Up @@ -6,15 +6,15 @@
#'@param file a \linkS4class{geojob} timeseries processing result file location
#'(See \code{\link{check}}).
#'@param delim the file delimiter
#'@param keep.units boolean for including a units column in returned data.frame
#'@param with.units boolean for including a units column in returned data.frame
#'@return a data.frame of timeseries values.
#'@keywords methods
#'@author Luke A. Winslow, Jordan S. Read
#'@export
#'@examples
#'local_file <- system.file('extdata','tsv_linear_ring.tsv', package = 'geoknife')
#'output <- parseTimeseries(local_file, delim = '\t')
parseTimeseries <- function(file, delim, keep.units = FALSE){
parseTimeseries <- function(file, delim, with.units = FALSE){

config = parseConfig(file, delim)

Expand Down Expand Up @@ -53,7 +53,7 @@ parseTimeseries <- function(file, delim, keep.units = FALSE){
'variable' = rep(as.character(config[['vars']][blk]), length.out = nrow(statData)),
'statistic' = rep(cleanStat, length.out = nrow(statData)))
)
if (keep.units){
if (with.units){
statData = cbind(statData, data.frame('units'=rep(units, length.out = nrow(statData))))
}
dataOut <- rbind(dataOut, statData)
Expand Down
14 changes: 6 additions & 8 deletions man/loadOutput-methods.Rd
Expand Up @@ -6,13 +6,15 @@
\alias{loadOutput,geojob-method}
\title{parse process output into R environment}
\usage{
loadOutput(.Object)
loadOutput(.Object, ...)

\S4method{loadOutput}{geojob}(.Object)
\S4method{loadOutput}{geojob}(.Object, ...)
}
\arguments{
\item{.Object}{a \code{\link{geojob}} object with a successful processID.
(See \code{\link{check}}).}

\item{...}{additional arguments passed to parsers (e.g., keep.units = TRUE)}
}
\value{
data.frame of timeseries values.
Expand All @@ -25,12 +27,8 @@ a \code{geojob} method for loading data into R from a completed processing reque
}
\examples{
\dontrun{
wp <- quick_wp()
job <- geoknife(stencil = c(-89,42), fabric = 'prism', knife = wp)
check(job)

Sys.sleep(10) # give it some time to process
loadOutput(job) # load and print output
job <- geoknife(stencil = c(-89,42), fabric = 'prism', wait = TRUE)
loadOutput(job, with.units = TRUE) # load and print output
}
}
\author{
Expand Down
4 changes: 2 additions & 2 deletions man/parseTimeseries.Rd
Expand Up @@ -4,15 +4,15 @@
\alias{parseTimeseries}
\title{parse timeseries file into R environment}
\usage{
parseTimeseries(file, delim, keep.units = FALSE)
parseTimeseries(file, delim, with.units = FALSE)
}
\arguments{
\item{file}{a \linkS4class{geojob} timeseries processing result file location
(See \code{\link{check}}).}

\item{delim}{the file delimiter}

\item{keep.units}{boolean for including a units column in returned data.frame}
\item{with.units}{boolean for including a units column in returned data.frame}
}
\value{
a data.frame of timeseries values.
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-geoknife_output_parser.R
Expand Up @@ -9,10 +9,10 @@ test_that("loadOutput fails with no process", {

test_that("timeseries parser works on multi feature, single variable", {
local_file <- system.file('extdata','tsv_multi_feature.tsv', package = 'geoknife')
output <- parseTimeseries(local_file, delim = '\t', keep.units = T)
output <- parseTimeseries(local_file, delim = '\t', with.units = T)
expect_is(output, "data.frame")
expect_true('units' %in% names(output))
output <- parseTimeseries(local_file, delim = '\t', keep.units = F)
output <- parseTimeseries(local_file, delim = '\t', with.units = F)
expect_false('units' %in% names(output))
})

Expand Down

0 comments on commit f016bc1

Please sign in to comment.