Skip to content

Commit

Permalink
Merge pull request #55 from philsf/release-0.6.3
Browse files Browse the repository at this point in the history
Release 0.6.3
  • Loading branch information
philsf authored Oct 22, 2018
2 parents 23b7e34 + 049071d commit 9205789
Show file tree
Hide file tree
Showing 27 changed files with 153 additions and 54 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: philsfmisc
Type: Package
Title: philsf's miscellaneous R functions
Version: 0.6.2
Version: 0.6.3
Authors@R: person("Felipe", "Figueiredo", email = "[email protected]", role = c("aut", "cre"))
Description: Miscellaneous R functions for convenient data analyses.
License: file LICENSE
Expand All @@ -10,3 +10,5 @@ LazyData: true
URL: https://github.com/philsf/philsfmisc
Depends: R (>= 3.3.0)
RoxygenNote: 6.1.0
Imports:
stringr
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export(logvar2cv)
export(predint)
importFrom(stats,qt)
importFrom(stats,sd)
importFrom(stringr,str_remove)
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# philsfmisc 0.6.3

- Revert the default of pct.symbol to FALSE (#49)
- Percentage intervals are now correctly formatted (#35, #53)
- adds depencency: stringr
- All functions now have description and details sections (#33)

# philsfmisc 0.6.2

- Now uses `roxygen2` for function documentation creation ( #37 )
Expand Down
6 changes: 4 additions & 2 deletions R/cv2logsd.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#' Convert the CV from a log-normal variable to the log-transformed standard deviation.
#' Convert the CV to the log10 sd (log-normal variable).
#'
#' @description
#' \code{cv2logsd} converts the CV from a log-normal variable to the log10-transformed standard deviation.
#'
#' This function converts the CV to the log10-transformed standard deviation, by taking the square root of \code{cv2logvar}.
#'
#' @param x A numeric value, vector or list.
#'
Expand Down
6 changes: 4 additions & 2 deletions R/cv2logvar.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#' Convert the CV from a log-normal variable to the log-transformed variance.
#' Convert the CV to the log10 var (log-normal variable).
#'
#' @description
#' \code{cv2logsd} converts the CV from a log-normal variable to the log10-transformed variance.
#'
#' This function converts the CV to the log10-transformed variance by inverting the formula used in \code{logvar2cv}.
#'
#' @param x A numeric value, vector or list.
#'
Expand Down
10 changes: 9 additions & 1 deletion R/format.float.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#' Format numbers for printing
#'
#' @description Format numbers, given a `digits` argument as significant decimal places.
#' \code{format.float} prepares numbers for results printing.
#'
#' This function formats numbers with the given number of decimal digits.
#' Numbers are always assumed to be \code{\link[base]{double}}.
#' If there is a percent sign in \code{x}, it is removed prior to formatting.
#'
#' @param x Value to be formatted.
#' Input can be a numeric or character value.
Expand All @@ -18,15 +21,20 @@
#' # Input is character
#' format.float("1.12543")
#' format.float(c("1.756", "1.823"))
#' # Input is percentage
#' format.float("10%", 1)
#' format.float("15 %", 1)
#'
#' # Useful for data frames
#' DF <- data.frame(num = c(1.756, 1.823), char = c("1.756", "1.823"), stringsAsFactors = FALSE)
#' transform(DF, num = format.float(num), char = format.float(char))
#'
#' @author Felipe Figueiredo
#' @importFrom stringr str_remove
#' @export format.float

format.float <- function(x, digits = 2) {
x <- stringr::str_remove(x, "%")
x <- suppressWarnings(as.numeric(x))
x <- formatC(x, format = "f", digits = digits)
x
Expand Down
9 changes: 8 additions & 1 deletion R/format.interval.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#' Format intervals for printing
#'
#' @description Format intervals, given a `digits` argument as significant decimal places.
#' \code{format.interval} prepares intervals for results printing.
#'
#' This function formats a given interval with the given number of decimal digits.
#' \code{interval} is always assumed to be a two valued vector of \code{\link[base]{double}}.
#' If there is a percent sign in any of \code{interval} values, it is removed prior to formatting by \code{format.float}.
#'
#' @param interval Must be a vector of two values.
#' Values can be either numeric or character.
Expand All @@ -16,6 +20,9 @@
#' # Input is character
#' format.interval(c("1.756", "1.823"))
#'
#' # Input is percentage
#' format.interval(c("10%", "15%"), 1)
#'
#' @author Felipe Figueiredo
#' @export format.interval

Expand Down
9 changes: 6 additions & 3 deletions R/format.pct.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#' Convenience function to format proportions as percentages
#' Format proportions as percentages for printing
#'
#' @description
#' \code{format.pct} prepares proportions as percentages for results printing, possibly with a percent sign.
#'
#' This function multiplies the proportion by 100, formats with the given number of decimal digits.
#' It also (optionally) includes a percent sign.
#'
#' @param p a numeric vector assumed to be a proportion.
#' @param digits the number of decimal digits to be used in the output.
Expand All @@ -20,7 +23,7 @@
#' @author Felipe Figueiredo
#' @export format.pct

format.pct <- function(p, digits = 1, pct.symbol = FALSE) {
format.pct <- function(p, digits = 1, pct.symbol = TRUE) {
symbol <- "%"
if (!pct.symbol) symbol <- NULL
paste0(format.float(p*100, digits), symbol)
Expand Down
5 changes: 4 additions & 1 deletion R/geocv.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#' Compute the CV of log-normally distributed data.
#'
#' @description
#' \code{geocv} computes the CV of log-normal data.
#'
#' This function first log10-transforms the original data \code{x}.
#' It then passes the standard deviation of the result to \code{logsd2cv}.
#'
#' @param x A numeric value, vector or list.
#' @param na.rm (logical) whether or not to remove \code{NA} values from computation
Expand Down
5 changes: 4 additions & 1 deletion R/geomean.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#' Compute the geometric mean
#'
#' @description
#' \code{geomean} computes the anti-log of the \code{mean} of log10-transformed data.
#'
#' This function first log10-transforms the original data \code{x}.
#' It then back-transforms the \code{mean} of the results from the log10 scale.
#'
#' @param x A numeric value, vector or list.
#'
Expand Down
8 changes: 5 additions & 3 deletions R/geosd.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#' Compute the "geometric standard deviation" of data
#' Compute the "geometric standard deviation" of log-normal data.
#'
#' @description The "geometric standard deviation" is not as well-defined as the geometric mean.
#' This function returns the analogous concept of \code{sd} in the same manner of the geometric mean.
#' \code{geosd} computes the anti-log of the standard deviation of log10-transformed data.
#'
#' The "geometric standard deviation" is not as well-defined as the geometric mean.
#' Here we apply the analogous concept of the geometric mean to the \code{sd}.
#'
#' @param x A numeric value, vector or list.
#'
Expand Down
16 changes: 9 additions & 7 deletions R/is.within.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#' Check if number is within given interval
#' Test if number is within given interval
#'
#' @description
#' \code{is.within} tests if object \code{x} is within \code{interval}.
#'
#' @param value A numeric value, vector or list.
#' @param interval The (numeric) interval within which \code{value} is being tested.
#' This function tests if the given value is contained within a (possibly open) given interval.
#'
#' @param x A numeric x, vector or list.
#' @param interval The (numeric) interval within which \code{x} is being tested.
#' @param open.interval logical: should \code{interval} be regarded as an open interval?
#'
#' @return The default method for \code{is.within} applied to an atomic vector returns
Expand All @@ -19,7 +21,7 @@
#' @author Felipe Figueiredo
#' @export is.within

is.within <- function(value, interval, open.interval = FALSE) {
if (open.interval) return( value > interval[1] & value < interval[2] )
value >= interval[1] & value <= interval[2]
is.within <- function(x, interval, open.interval = FALSE) {
if (open.interval) return( x > interval[1] & x < interval[2] )
x >= interval[1] & x <= interval[2]
}
9 changes: 6 additions & 3 deletions R/logsd2cv.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#' Convert the log-transformed standard deviation from a log-normal variable to the CV.
#' Convert the log10 standard deviation to the CV (log-normal variable).
#'
#' @description
#' \code{logsd2cv} the log10-transformed \code{sd} from a log-normal variable to the CV.
#'
#' @param x A numeric value, vector or list.
#' This function converts the log10-transformed standard deviation of a log-normal variable to the CV.
#'
#' @param x The log10-transformed \code{sd} of data.
#' A numeric value, vector or list.
#'
#' @return Returns the geometric CV (as percentage)
#'
Expand Down
9 changes: 6 additions & 3 deletions R/logvar2cv.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#' Convert the log-transformed variance from a log-normal variable to the CV.
#' Convert the log10 variance to the CV (log-normal variable).
#'
#' @description
#' \code{logvar2cv} converts the log10-transformed \code{var} of a log-normal variable to the CV.
#'
#' @param x A numeric value, vector or list.
#' This function converts the log10-transformed variance of a log-normal variable to the CV.
#'
#' @param x The log10-transformed \code{var} of data.
#' A numeric value, vector or list.
#'
#' @return Returns the geometric CV (as percentage)
#'
Expand Down
4 changes: 3 additions & 1 deletion R/predint.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#' Prediction Intervals for given data
#'
#' @description Compute a prediction interval of a vector, which is assumed
#' \code{predint} computes a prediction interval of Normal data.
#'
#' This function computes a prediction interval of a vector, which is assumed
#' normally distributed with unknown mean and variance.
#'
#' @param datavector A numeric value, vector or list.
Expand Down
7 changes: 5 additions & 2 deletions man/cv2logsd.Rd

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

7 changes: 5 additions & 2 deletions man/cv2logvar.Rd

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

9 changes: 8 additions & 1 deletion man/format.float.Rd

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

10 changes: 9 additions & 1 deletion man/format.interval.Rd

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

10 changes: 7 additions & 3 deletions man/format.pct.Rd

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

6 changes: 5 additions & 1 deletion man/geocv.Rd

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

5 changes: 4 additions & 1 deletion man/geomean.Rd

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

7 changes: 5 additions & 2 deletions man/geosd.Rd

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

Loading

0 comments on commit 9205789

Please sign in to comment.