diff --git a/DESCRIPTION b/DESCRIPTION index 8337dea..a2acba8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: philsfmisc Type: Package Title: philsf's miscellaneous R functions -Version: 0.5.1 +Version: 0.6.0 Authors@R: person("Felipe", "Figueiredo", email = "philsf79@gmail.com", role = c("aut", "cre")) Description: Miscellaneous R functions for convenient data analyses. License: GPL-2 diff --git a/R/cv2logsd.R b/R/cv2logsd.R index 217abd9..ec9d318 100644 --- a/R/cv2logsd.R +++ b/R/cv2logsd.R @@ -1,4 +1,4 @@ -cv2logsd <- function(CV) { - SD <- sqrt( cv2logvar(CV) ) +cv2logsd <- function(x) { + SD <- sqrt( cv2logvar(x) ) SD } diff --git a/R/cv2logvar.R b/R/cv2logvar.R index e9651e0..f61aae5 100644 --- a/R/cv2logvar.R +++ b/R/cv2logvar.R @@ -1,4 +1,4 @@ -cv2logvar <- function( CV ) { - VAR <- (log((CV/100)^2 + 1))/(log(10)^2) +cv2logvar <- function( x ) { + VAR <- (log((x/100)^2 + 1))/(log(10)^2) VAR } diff --git a/R/format.float.R b/R/format.float.R index 13e835a..c423fa3 100644 --- a/R/format.float.R +++ b/R/format.float.R @@ -1,5 +1,5 @@ -format.float <- function(value, digits = 2) { - value <- suppressWarnings(as.numeric(value)) - value <- formatC(value, format = "f", digits = digits) - value +format.float <- function(x, digits = 2) { + x <- suppressWarnings(as.numeric(x)) + x <- formatC(x, format = "f", digits = digits) + x } diff --git a/R/format.pct.R b/R/format.pct.R new file mode 100644 index 0000000..278919e --- /dev/null +++ b/R/format.pct.R @@ -0,0 +1,5 @@ +format.pct <- function(p, digits = 1, pct.symbol = TRUE) { + symbol <- "%" + if (!pct.symbol) symbol <- NULL + paste0(format.float(p*100, digits), symbol) +} diff --git a/R/geocv.R b/R/geocv.R index 21a255a..a181148 100644 --- a/R/geocv.R +++ b/R/geocv.R @@ -1,4 +1,4 @@ -geocv <- function(datavector, digits = 2, na.rm = TRUE) { - logsd <- sd(log10(datavector), na.rm = na.rm) - logsd2cv(logsd, digits = digits, na.rm = na.rm) +geocv <- function(x, na.rm = TRUE) { + logsd <- sd(log10(x), na.rm = na.rm) + logsd2cv(logsd) } diff --git a/R/geomean.R b/R/geomean.R index 3b6af7e..15d4a4f 100644 --- a/R/geomean.R +++ b/R/geomean.R @@ -1,4 +1,4 @@ -geomean <- function(datavector) { - datavector[(datavector == 0)] <- NA # discard null values - 10^mean(log10(datavector), na.rm = T) +geomean <- function(x) { + x[(x == 0)] <- NA # discard null values + 10^mean(log10(x), na.rm = T) } diff --git a/R/geosd.R b/R/geosd.R index 84574bf..6d2a657 100644 --- a/R/geosd.R +++ b/R/geosd.R @@ -1,3 +1,3 @@ -geosd <- function(datavector) { - 10^sd(log10(datavector)) +geosd <- function(x) { + 10^sd(log10(x)) } diff --git a/R/logsd2cv.R b/R/logsd2cv.R index 34ae5e4..7958a1f 100644 --- a/R/logsd2cv.R +++ b/R/logsd2cv.R @@ -1,3 +1,3 @@ -logsd2cv <- function(logsd, digits = 2, na.rm = TRUE) { - round(sqrt(exp((log(10)^2)*logsd^2) - 1)*100 , digits) +logsd2cv <- function(x) { + sqrt(exp((log(10)^2)*x^2) - 1)*100 } diff --git a/R/logvar2cv.R b/R/logvar2cv.R index 478d91d..953e84e 100644 --- a/R/logvar2cv.R +++ b/R/logvar2cv.R @@ -1,3 +1,3 @@ -logvar2cv <- function(var, digits = 2, na.rm = TRUE) { - round(sqrt(exp((log(10)^2)*var) - 1)*100 , digits) +logvar2cv <- function(x) { + sqrt(exp((log(10)^2)*x) - 1)*100 } diff --git a/README.md b/README.md index c4ba16c..a64a828 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,15 @@ To install the *development* version, use the following command: - `format.float` - `format.interval` +- `format.pct` - `is.within` - `geomean` - `geosd` - `geocv` - `logsd2cv` +- `logvar2cv` +- `cv2logsd` +- `cv2logvar` - `predint` ## Report template diff --git a/inst/rmarkdown/templates/Relatorio/skeleton/misc/style.docx b/inst/rmarkdown/templates/Relatorio/skeleton/misc/style.docx old mode 100644 new mode 100755 index d9ecb2e..e4bdc61 Binary files a/inst/rmarkdown/templates/Relatorio/skeleton/misc/style.docx and b/inst/rmarkdown/templates/Relatorio/skeleton/misc/style.docx differ diff --git a/inst/rmarkdown/templates/Relatorio/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/Relatorio/skeleton/skeleton.Rmd index c1ce455..1820029 100644 --- a/inst/rmarkdown/templates/Relatorio/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/Relatorio/skeleton/skeleton.Rmd @@ -48,6 +48,29 @@ kable(history) --- +# Assinaturas + +```{r, echo=FALSE} +sig.field <- "__________________________" +date.field <- "_____________" +Stat <- c("Elaborador", "Nome", "Função", sig.field, date.field) +Reviewer <- c("Revisado por", "", "", sig.field, date.field) +Approver <- c("Verificado por", "", "", sig.field, date.field) +Final.Approver <- c("Aprovação final", "", "", sig.field, date.field) + +sigs <- rbind( + Stat + , Reviewer + , Approver + , Final.Approver + ) +rownames(sigs) <- NULL +colnames(sigs) <- c("Papel", "Nome", "Função", "Assinatura", "Data") + +# pander(sigs, split.cells = c(9, 14, 14, 16, 8), split.table = Inf) +kable(sigs) +``` + # Lista de abreviaturas # Introdução diff --git a/man/format.float.Rd b/man/format.float.Rd index 03abff4..c5bf37b 100644 --- a/man/format.float.Rd +++ b/man/format.float.Rd @@ -11,11 +11,11 @@ Format numbers, given a `digits` argument as significant decimal places. {Numbers are always assumed to be \code{\link[base]{double}}.} } \usage{ -format.float(x) +format.float(x, digits) } %- maybe also 'usage' for other objects documented here. \arguments{ - \item{value}{ + \item{x}{ Value to be formatted. Input can be a numeric or character value. } @@ -62,7 +62,7 @@ format.float("1.12543") format.float(c("1.756", "1.823")) # Useful for data frames -DF <- data.frame(num = c(1.756, 1.823), char = c("1.756", "1.823"), stringsAsFactors = F) +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)) } % Add one or more standard keywords, see file 'KEYWORDS' in the diff --git a/man/format.interval.Rd b/man/format.interval.Rd index d086a14..8ab960f 100644 --- a/man/format.interval.Rd +++ b/man/format.interval.Rd @@ -53,7 +53,7 @@ Felipe Figueiredo \examples{ format.interval(c(1.756, 1.823)) -format.interval(1.5, 1) # error: 1.5 is not an interval +# format.interval(1.5, 1) # error: 1.5 is not an interval # Input is character format.interval(c("1.756", "1.823")) diff --git a/man/format.pct.Rd b/man/format.pct.Rd new file mode 100644 index 0000000..c85f229 --- /dev/null +++ b/man/format.pct.Rd @@ -0,0 +1,51 @@ +\name{format.pct} +\alias{format.pct} +%- Also NEED an '\alias' for EACH other topic documented here. +\title{ +Convenience function to format proportions as percentages +} +\description{ +%% ~~ A concise (1-5 lines) description of what the function does. ~~ +} +\usage{ +format.pct(p, digits = 1, pct.symbol = TRUE) +} +%- maybe also 'usage' for other objects documented here. +\arguments{ + \item{p}{a numeric vector assumed to be a proportion.} + \item{digits}{the number of decimal digits to be used in the output.} + \item{pct.symbol}{(logical) whether or not to include the percent sign in the output.} +} +\details{ +%% ~~ If necessary, more details than the description above ~~ +} +\value{ +A character value formatted as percentages} +\references{ +%% ~put references to the literature/web site here ~ +} +\author{ +%% ~~who you are~~ +} +\note{ +%% ~~further notes~~ +} + +%% ~Make other sections like Warning with \section{Warning }{....} ~ + +\seealso{ +%% ~~objects to See Also as \code{\link{help}}, ~~~ +} +\examples{ +format.pct(.1) +format.pct(c(.42, .99), 0) + +m <- 10*matrix(c(1, 1.1, .9, 2), nrow = 2) +format.pct(fisher.test(m)$p.value) +format.pct(fisher.test(5*m)$p.value) +format.pct(fisher.test(m)$conf.int) +} +% Add one or more standard keywords, see file 'KEYWORDS' in the +% R documentation directory. +\keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS") +\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line diff --git a/man/geocv.Rd b/man/geocv.Rd index ec53f9f..5f81f4f 100644 --- a/man/geocv.Rd +++ b/man/geocv.Rd @@ -8,15 +8,12 @@ %% ~~ A concise (1-5 lines) description of what the function does. ~~ } \usage{ -geocv(x, digits = 2, na.rm = TRUE) +geocv(x, na.rm = TRUE) } %- maybe also 'usage' for other objects documented here. \arguments{ \item{x}{ %% ~~Describe \code{x} here~~ -} - \item{digits}{ -%% ~~Describe \code{digits} here~~ } \item{na.rm}{ %% ~~Describe \code{na.rm} here~~ diff --git a/man/predint.Rd b/man/predint.Rd index e72ffad..5da3a77 100644 --- a/man/predint.Rd +++ b/man/predint.Rd @@ -4,7 +4,7 @@ \title{Prediction Intervals for given data %% ~~function to do ... ~~ } -\description{Compute a prediction of a vector, which is assumed normally distributed with unknown mean and variance. +\description{Compute a prediction interval of a vector, which is assumed normally distributed with unknown mean and variance. %% ~~ A concise (1-5 lines) description of what the function does. ~~ } \usage{