Skip to content

Commit

Permalink
Release 1.1-0
Browse files Browse the repository at this point in the history
  • Loading branch information
Arni Magnusson committed Apr 27, 2017
1 parent 052e2b5 commit fd31ce3
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 2 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: icesTAF
Version: 1.0-0
Date: 2017-02-17
Version: 1.1-0
Date: 2017-04-27
Title: Functions to Support the ICES Transparent Assessment Framework
Authors@R: c(person("Arni", "Magnusson", role=c("aut","cre"), email="[email protected]"),
person("Colin", "Millar", role="aut"))
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

export(dir.remove)
export(dos2unix)
export(flr2taf)
export(readDLS)
export(taf2long)
export(unix2dos)
export(writeDLS)
8 changes: 8 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
--------------------------------------------------------------------------------
icesTAF 1.1-0 (2017-04-27)
--------------------------------------------------------------------------------
o Added functions flr2taf() and taf2long() to convert between table formats.




--------------------------------------------------------------------------------
icesTAF 1.0-0 (2017-02-17)
--------------------------------------------------------------------------------
Expand Down
44 changes: 44 additions & 0 deletions R/flr2taf.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#' Convert FLR table to TAF format
#'
#' Convert a simple crosstab table from FLR format to TAF format.
#'
#' @param x a table of class \code{FLQuant}.
#' @param na a value that should be converted to NA.
#' @param year whether the year should be stored in the first column, instead of
#' row names.
#'
#' @note
#' FLR uses the \code{FLQuant} class to store tables as 6-dimensional arrays,
#' while TAF crosstabs are stored as data frames with a year column.
#'
#' @seealso
#' \code{\link{as.data.frame}} is a method provided by the \pkg{FLCore} package
#' to convert \code{FLQuant} tables to a 7-column long format.
#'
#' \code{\link{taf2long}} converts TAF tables to long format.
#'
#' \code{\link{icesTAF-package}} gives an overview of the package.
#'
#' @examples
#' x <- array(round(runif(70)/3, 1), dim=c(7,10,1,1,1,1))
#' dimnames(x) <- list(age=2:8, year=1991:2000,
#' unit="unique", season="all", area="unique", iter=1)
#' flr2taf(x)
#' flr2taf(x, na=0, year=FALSE)
#'
#' @export

flr2taf <- function(x, na=NULL, year=TRUE)
{
y <- as.data.frame(t(drop(unclass(x))))
if(year)
{
y <- cbind(Year=as.integer(row.names(y)), y)
row.names(y) <- NULL
}
if(!is.null(na))
{
y[y==na] <- NA
}
y
}
5 changes: 5 additions & 0 deletions R/icesTAF-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#' \code{\link{readDLS}} \tab read \code{DLS3.2} output from file\cr
#' \code{\link{writeDLS}} \tab write \code{DLS3.2} output to file
#' }
#' \emph{Table converters:}
#' \tabular{ll}{
#' \code{\link{flr2taf}} \tab from FLR to TAF format\cr
#' \code{\link{taf2long}} \tab from TAF to long format
#' }
#' \emph{File management:}
#' \tabular{ll}{
#' \code{\link{dir.remove}} \tab remove empty directories\cr
Expand Down
41 changes: 41 additions & 0 deletions R/taf2long.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#' Convert TAF table to long format
#'
#' Convert a table from TAF crosstab format to a 3-column long format.
#'
#' @param x a data frame containing crosstab data.
#' @param names a vector of three column names for the resulting data frame.
#' @param year whether the input table has year in the first column, instead of
#' row names.
#'
#' @note
#' TAF stores crosstab tables as data frames with a year column, as seen in
#' stock assessment reports. The long format is practical for analysis and
#' producing plots.
#'
#' @seealso
#' \code{\link{flr2taf}} converts tables from FLR to TAF format.
#'
#' \code{\link{icesTAF-package}} gives an overview of the package.
#'
#' @examples
#' fish <- matrix(round(runif(30),3), 5)
#' fish <- data.frame(Year=2001:2005, fish, check.names=FALSE)
#' taf2long(fish)
#'
#' alt <- fish[-1]
#' row.names(alt) <- fish$Year
#' taf2long(alt, names=c("Year","Age","Weight"), year=FALSE)
#'
#' @export

taf2long <- function(x, names=c("Year","Age","Value"), year=TRUE)
{
if(year)
{
row.names(x) <- x[[1]]
x <- x[-1]
}
y <- as.data.frame(as.table(as.matrix(x)))
names(y) <- names
y
}
39 changes: 39 additions & 0 deletions man/flr2taf.Rd

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

5 changes: 5 additions & 0 deletions man/icesTAF-package.Rd

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

39 changes: 39 additions & 0 deletions man/taf2long.Rd

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

0 comments on commit fd31ce3

Please sign in to comment.