Skip to content

Commit

Permalink
first draft of a tidy output function
Browse files Browse the repository at this point in the history
  • Loading branch information
nevrome committed Jul 23, 2017
1 parent f35124f commit af2cc5c
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ S3method(get_sigma_ranges,oxcAARCalibratedDatesList)
S3method(get_std,default)
S3method(get_std,oxcAARCalibratedDate)
S3method(get_std,oxcAARCalibratedDatesList)
S3method(get_tidy_oxcalresult,default)
S3method(get_tidy_oxcalresult,oxcAARCalibratedDate)
S3method(get_tidy_oxcalresult,oxcAARCalibratedDatesList)
S3method(plot,oxcAARCalibratedDate)
S3method(plot,oxcAARCalibratedDatesList)
S3method(print,oxcAARCalibratedDate)
Expand All @@ -32,6 +35,7 @@ export(get_name)
export(get_raw_probabilities)
export(get_sigma_ranges)
export(get_std)
export(get_tidy_oxcalresult)
export(is.oxcAARCalibratedDate)
export(is.oxcAARCalibratedDatesList)
export(oxcAARCalibratedDate)
Expand Down
58 changes: 58 additions & 0 deletions R/tidy_output.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#' @name get_tidy_oxcalresult
#' @title tidy output
#'
#' @description Transforms oxcAAR output to a tidy data format.
#' See \url{http://vita.had.co.nz/papers/tidy-data.html} and
#' \url{https://cran.r-project.org/web/packages/broom/vignettes/broom.html}
#'
#' @param x an object of class oxcAARCalibratedDate or oxcAARCalibratedDatesList
#'
#' @return a data.frame (with list columns)
#' @export
#'
#' @rdname get_tidy_oxcalresult
#' @examples
#' \dontrun{
#' x <- oxcalCalibrate(c(5000, 4500, 3000), c(20, 50, 60))
#' get_tidy_oxcalresult(x)
#' y <- oxcalCalibrate(5000, 20)[[1]]
#' get_tidy_oxcalresult(y)
#' }
#'
get_tidy_oxcalresult <- function(x) {
UseMethod("get_tidy_oxcalresult")
}

#' @rdname get_tidy_oxcalresult
#' @export
get_tidy_oxcalresult.default <- function(x) {
stop("x is not an object of class oxcAARCalibratedDate or oxcAARCalibratedDatesList")
}

#' @rdname get_tidy_oxcalresult
#' @export
get_tidy_oxcalresult.oxcAARCalibratedDate <- function(x) {
res <- data.frame(
name = get_name(x),
bp = get_bp(x),
std = get_std(x),
cal_curve = get_cal_curve(x),
sigma_ranges = I(list(get_sigma_ranges(x))),
raw_probabilities = I(list(get_raw_probabilities(x)))
)
return(res)
}

#' @rdname get_tidy_oxcalresult
#' @export
get_tidy_oxcalresult.oxcAARCalibratedDatesList <- function(x) {
res <- data.frame(
name = get_name(x),
bp = get_bp(x),
std = get_std(x),
cal_curve = get_cal_curve(x),
sigma_ranges = I(get_sigma_ranges(x)),
raw_probabilities = I(get_raw_probabilities(x))
)
return(res)
}
37 changes: 37 additions & 0 deletions man/get_tidy_oxcalresult.Rd

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

0 comments on commit af2cc5c

Please sign in to comment.