Skip to content

Commit

Permalink
Rename fdim -> ddim
Browse files Browse the repository at this point in the history
  • Loading branch information
arni-magnusson committed Dec 11, 2023
1 parent 6273471 commit 3905f72
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 157 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export(clean.library)
export(clean.software)
export(convert.spaces)
export(cp)
export(ddim)
export(deps)
export(detach.packages)
export(div)
Expand All @@ -23,7 +24,6 @@ export(draft.software)
export(ds.file)
export(ds.package)
export(extract.subdir)
export(fdim)
export(file.encoding)
export(flr2taf)
export(get.remote.sha)
Expand Down
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TAF 4.3.0 (2023-11-26)
# TAF 4.3.0 (2023-12-11)

* Added function fdim() to show the dimensions of an FLR table.
* Added function ddim() to show the data dimensions of a table.

* Added function taf.libraries() to load all packages from TAF library. Code
contributed by Iago Mosqueira.
Expand Down
2 changes: 1 addition & 1 deletion R/TAF-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
#' }
#' \emph{Tables:}
#' \tabular{ll}{
#' \code{\link{ddim}} \tab show data dimensions\cr
#' \code{\link{div}} \tab divide column values\cr
#' \code{\link{fdim}} \tab show FLR dimensions\cr
#' \code{\link{flr2taf}} \tab convert FLR to TAF\cr
#' \code{\link{long2taf}} \tab convert long format to TAF\cr
#' \code{\link{long2xtab}} \tab convert long format to crosstab\cr
Expand Down
47 changes: 47 additions & 0 deletions R/ddim.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#' Data Dimensions
#'
#' Show the data dimensions of a table.
#'
#' @param x a data frame where the first columns are dimension variables and the
#' last column is a measurement variable.
#' @param reduce is whether to omit single-level dimensions.
#'
#' @details
#' Dimension variables can include year, age, region, fleet, survey, or the
#' like, generally an integer or string. The measurement variable can be catch,
#' fishing mortality, maturity, weight, or the like, often a decimal.
#'
#' \code{x} can also be an FLR table in \code{FLQuant} format.
#'
#' @return Named vector showing the dimension names and number of levels.
#'
#' @seealso
#' \code{\link{unique}} is the base function to extract the levels of a
#' dimension variable.
#'
#' \code{\link{TAF-package}} gives an overview of the package.
#'
#' @examples
#' # Long table format, 8 years and 4 ages
#' ddim(catage.long)
#'
#' # Some base R datasets
#' ddim(esoph[-5])
#' ddim(rev(warpbreaks))
#' ddim(rev(ToothGrowth))
#'
#' @importFrom methods is
#' @importFrom stats setNames
#'
#' @export

ddim <- function(x, reduce=FALSE)
{
out <- if(is(x, "FLQuant"))
setNames(dim(x), names(dimnames(x)))
else
sapply(x, function(col) length(unique(col)))[-ncol(x)]
if(reduce)
out <- out[out != 1]
out
}
56 changes: 0 additions & 56 deletions R/fdim.R

This file was deleted.

2 changes: 0 additions & 2 deletions R/flr2taf.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#' \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{fdim}} shows the dimensions of an FLR table.
#'
#' \code{\link{TAF-package}} gives an overview of the package.
#'
#' @examples
Expand Down
2 changes: 1 addition & 1 deletion man/TAF-package.Rd

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

43 changes: 43 additions & 0 deletions man/ddim.Rd

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

52 changes: 0 additions & 52 deletions man/fdim.Rd

This file was deleted.

2 changes: 0 additions & 2 deletions man/flr2taf.Rd

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

73 changes: 33 additions & 40 deletions tests/Examples/TAF-Ex.Rout.save
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

R version 4.3.1 (2023-06-16) -- "Beagle Scouts"
R version 4.3.2 (2023-10-31) -- "Eye Holes"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

Expand Down Expand Up @@ -353,6 +353,37 @@ Type 'q()' to quit R.
>
>
> cleanEx()
> nameEx("ddim")
> ### * ddim
>
> flush(stderr()); flush(stdout())
>
> ### Name: ddim
> ### Title: Data Dimensions
> ### Aliases: ddim
>
> ### ** Examples
>
> # Long table format, 8 years and 4 ages
> ddim(catage.long)
Year Age
8 4
>
> # Some base R datasets
> ddim(esoph[-5])
agegp alcgp tobgp
6 4 4
> ddim(rev(warpbreaks))
tension wool
3 2
> ddim(rev(ToothGrowth))
dose supp
3 2
>
>
>
>
> cleanEx()
> nameEx("deps")
> ### * deps
>
Expand Down Expand Up @@ -550,44 +581,6 @@ Type 'q()' to quit R.
>
>
> cleanEx()
> nameEx("fdim")
> ### * fdim
>
> flush(stderr()); flush(stdout())
>
> ### Name: fdim
> ### Title: FLR Dimensions
> ### Aliases: fdim
>
> ### ** Examples
>
> ## Not run:
> ##D library(FLCore)
> ##D flq <- FLQuant(t(catage.xtab), dimnames=list(age=1:4, year=1963:1970))
> ##D df <- as.data.frame(flq)
> ##D fdim(flq)
> ##D fdim(df)
> ##D fdim(df, TRUE)
> ## End(Not run)
>
> # Any data frame where the last column is the measurement variable
> fdim(catage.long)
Year Age
8 4
> fdim(esoph[-5])
agegp alcgp tobgp
6 4 4
> fdim(rev(warpbreaks))
tension wool
3 2
> fdim(rev(ToothGrowth))
dose supp
3 2
>
>
>
>
> cleanEx()
> nameEx("file.encoding")
> ### * file.encoding
>
Expand Down Expand Up @@ -1825,7 +1818,7 @@ detaching ‘package:lattice’

> options(digits = 7L)
> base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n")
Time elapsed: 0.225 0.008 0.234 0 0
Time elapsed: 0.236 0.001 0.236 0 0
> grDevices::dev.off()
null device
1
Expand Down

0 comments on commit 3905f72

Please sign in to comment.