Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.6.2 #48

Merged
merged 40 commits into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c1b74a9
Merge tag 'v0.6.1' into develop
philsf Oct 5, 2018
1dbb5c7
estilos faltantes configurados
Oct 15, 2018
075713b
list styles reformatted
Oct 15, 2018
2fe08ea
estilo normal reformatado
Oct 15, 2018
6ffe9ae
estilos de sumário reformatados
Oct 15, 2018
02d7ea0
cabeçalho e rodapé ajustados ao novo estilo normal (parágrafo)
Oct 15, 2018
38e4afc
estilos reformatados - testados
Oct 15, 2018
123343b
keep_md by default
Oct 15, 2018
acf3549
report instead of CODE
Oct 15, 2018
1e52324
whitespace removed
Oct 15, 2018
5c78902
fix: paráfrafo 0cm antes/depois no header/footer
Oct 15, 2018
4332692
Merge pull request #46 from philsf/45-estilos
philsf Oct 15, 2018
13c58a8
DESCRIPTION roxygenized
philsf Oct 15, 2018
5c3e154
minimal roxygen comments (export + author)
philsf Oct 15, 2018
4a276d7
minimal import sections (sd and qt from stats)
philsf Oct 15, 2018
c5858cb
title and params for predint
philsf Oct 15, 2018
5480d57
roxygen comments for geomean
philsf Oct 15, 2018
58d139a
roxygen comments for format.pct
philsf Oct 15, 2018
a649bbb
roxygen comments for format.float
philsf Oct 15, 2018
f9b9c87
standardize order of roxygen tags
philsf Oct 15, 2018
39d7fab
roxygen tags for cv2logsd
philsf Oct 15, 2018
f35d05b
roxygen tags for cv2logvar
philsf Oct 15, 2018
5cb72b7
roxygen tags for format.interval
philsf Oct 16, 2018
7b77c29
roxygen tags for geosd
philsf Oct 16, 2018
c3ea6d5
roxygen tags for is.within
philsf Oct 16, 2018
a2b7bf7
roxygen tags for logsd2cv
philsf Oct 16, 2018
c421ef2
roxygen tags for logvar2cv
philsf Oct 16, 2018
cadc957
roxygen tags for predint
philsf Oct 16, 2018
3353e5a
roxygen tags for geocv
philsf Oct 16, 2018
5f07bb7
use roxygen in RStudio Project by default
philsf Oct 16, 2018
188b1cf
minimal description of param x in all functions
philsf Oct 16, 2018
96db025
fix example in geocv
philsf Oct 16, 2018
f39efb7
purge replicate tags
philsf Oct 16, 2018
7b6413c
minimal return tag descriptions
philsf Oct 16, 2018
fa4b0c9
manually export function names with dots (related to #38)
philsf Oct 16, 2018
b540210
documents auto-generated by roxygen
philsf Oct 16, 2018
cf7586c
NAMESPACE autogenerated by roxygen
philsf Oct 16, 2018
4ca46d8
Merge pull request #47 from philsf/37-roxygen-comments
philsf Oct 16, 2018
eeb7da9
version bump
philsf Oct 16, 2018
cc96fc0
NEWS updated, preparing for release
philsf Oct 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
Package: philsfmisc
Type: Package
Title: philsf's miscellaneous R functions
Version: 0.6.1
Version: 0.6.2
Authors@R: person("Felipe", "Figueiredo", email = "[email protected]", role = c("aut", "cre"))
Description: Miscellaneous R functions for convenient data analyses.
License: file LICENSE
Encoding: UTF-8
LazyData: true
URL: https://github.com/philsf/philsfmisc
Depends: R (>= 3.3.0)
RoxygenNote: 6.1.0
18 changes: 16 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
importFrom("stats", "qt", "sd")
exportPattern("^[[:alpha:]]+")
# Generated by roxygen2: do not edit by hand

export(cv2logsd)
export(cv2logvar)
export(format.float)
export(format.interval)
export(format.pct)
export(geocv)
export(geomean)
export(geosd)
export(is.within)
export(logsd2cv)
export(logvar2cv)
export(predint)
importFrom(stats,qt)
importFrom(stats,sd)
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# philsfmisc 0.6.2

- Now uses `roxygen2` for function documentation creation ( #37 )
- Styles updated for all templates ( #45 )

# philsfmisc 0.6.1

- Styles updated #41
Expand Down
15 changes: 15 additions & 0 deletions R/cv2logsd.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
#' Convert the CV from a log-normal variable to the log-transformed standard deviation.
#'
#' @description
#'
#' @param x A numeric value, vector or list.
#'
#' @return Returns log-transformed sd
#'
#' @examples
#' cv2logsd(50)
#' # [1] 0.2051523
#'
#' @author Felipe Figueiredo
#' @export

cv2logsd <- function(x) {
SD <- sqrt( cv2logvar(x) )
SD
Expand Down
15 changes: 15 additions & 0 deletions R/cv2logvar.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
#' Convert the CV from a log-normal variable to the log-transformed variance.
#'
#' @description
#'
#' @param x A numeric value, vector or list.
#'
#' @return Returns the log-transformed variance.
#'
#' @examples
#' cv2logvar(50)
#' # [1] 0.04208748
#'
#' @author Felipe Figueiredo
#' @export

cv2logvar <- function( x ) {
VAR <- (log((x/100)^2 + 1))/(log(10)^2)
VAR
Expand Down
28 changes: 28 additions & 0 deletions R/format.float.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
#' Format numbers for printing
#'
#' @description Format numbers, given a `digits` argument as significant decimal places.
#' Numbers are always assumed to be \code{\link[base]{double}}.
#'
#' @param x Value to be formatted.
#' Input can be a numeric or character value.
#'
#' @param digits Number of fixed digits, after decimal point
#'
#' @return Returns a character value.
#'
#' @examples
#' format.float(0.5)
#' format.float(0.672, 4)
#' format.float(1.4927, 1)
#' format.float(c(1.756, 1.823))
#' # Input is character
#' 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 = FALSE)
#' transform(DF, num = format.float(num), char = format.float(char))
#'
#' @author Felipe Figueiredo
#' @export format.float

format.float <- function(x, digits = 2) {
x <- suppressWarnings(as.numeric(x))
x <- formatC(x, format = "f", digits = digits)
Expand Down
21 changes: 21 additions & 0 deletions R/format.interval.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
#' Format intervals for printing
#'
#' @description Format intervals, given a `digits` argument as significant decimal places.
#'
#' @param interval Must be a vector of two values.
#' Values can be either numeric or character.
#'
#' @param digits Number of fixed digits, after decimal point.
#'
#' @return Returns a character value.
#'
#' @examples
#' format.interval(c(1.756, 1.823))
#' # format.interval(1.5, 1) # error: 1.5 is not an interval
#'
#' # Input is character
#' format.interval(c("1.756", "1.823"))
#'
#' @author Felipe Figueiredo
#' @export format.interval

format.interval <- function(interval, digits = 2) {
if (is.null(interval)) return(NULL) # if no argument passed, return
if (anyNA(interval)) return(NA) # return NA in case of incomplete interval
Expand Down
22 changes: 22 additions & 0 deletions R/format.pct.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
#' Convenience function to format proportions as percentages
#'
#' @description
#'
#' @param p a numeric vector assumed to be a proportion.
#' @param digits the number of decimal digits to be used in the output.
#' @param pct.symbol (logical) whether or not to include the percent sign in the output.
#'
#' @return A character value formatted as percentages
#'
#' @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)
#'
#' @author Felipe Figueiredo
#' @export format.pct

format.pct <- function(p, digits = 1, pct.symbol = FALSE) {
symbol <- "%"
if (!pct.symbol) symbol <- NULL
Expand Down
18 changes: 18 additions & 0 deletions R/geocv.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
#' Compute the CV of log-normally distributed data.
#'
#' @description
#'
#' @param x A numeric value, vector or list.
#' @param na.rm (logical) whether or not to remove \code{NA} values from computation
#'
#' @return Returns the geometric CV (as percentage)
#'
#' @examples
#' d <- c(10,100,1000)
#' geocv(d)
#' geocv(d) == logsd2cv(1)
#'
#' @author Felipe Figueiredo
#' @export
#' @importFrom stats sd

geocv <- function(x, na.rm = TRUE) {
logsd <- sd(log10(x), na.rm = na.rm)
logsd2cv(logsd)
Expand Down
18 changes: 18 additions & 0 deletions R/geomean.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
#' Compute the geometric mean
#'
#' @description
#'
#' @param x A numeric value, vector or list.
#'
#' @details If any null values are present in \code{x} they are first replaced with \code{NA}.
#'
#' @return Returns the geometric mean of \code{x}.
#'
#' @examples
#' d <- c(10,100,1000)
#' geomean(d)
#' geomean(c(d,0)) # na.rm is TRUE by default for sd()
#'
#' @author Felipe Figueiredo
#' @export

geomean <- function(x) {
x[(x == 0)] <- NA # discard null values
10^mean(log10(x), na.rm = T)
Expand Down
18 changes: 18 additions & 0 deletions R/geosd.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
#' Compute the "geometric standard deviation" of 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.
#'
#' @param x A numeric value, vector or list.
#'
#' @return The anti-log of the \code{sd} of log-transformed data `x`.
#' Base 10 is assumed as a fixed default in this version.
#'
#' @examples
#' d <- c(10,100,1000)
#' geosd(d)
#'
#' @author Felipe Figueiredo
#' @export
#' @importFrom stats sd

geosd <- function(x) {
10^sd(log10(x))
}
21 changes: 21 additions & 0 deletions R/is.within.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
#' Check if number is within given interval
#'
#' @description
#'
#' @param value A numeric value, vector or list.
#' @param interval The (numeric) interval within which \code{value} 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
#' a logical vector of the same length as its argument x, containing TRUE for those elements contained within \code{interval}, and FALSE otherwise.
#'
#' @examples
#' is.within(1.5, c(0,5)) # TRUE
#' is.within(6, c(0,5)) # FALSE
#'
#' is.within(c(1.5, 6), c(0,5)) # vector: TRUE, TRUE
#' is.within(list(1.5, 6), c(0,5)) # list: TRUE, FALSE
#'
#' @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]
Expand Down
16 changes: 16 additions & 0 deletions R/logsd2cv.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
#' Convert the log-transformed standard deviation from a log-normal variable to the CV.
#'
#' @description
#'
#' @param x A numeric value, vector or list.
#'
#' @return Returns the geometric CV (as percentage)
#'
#' @examples
#' d <- c(10,100,1000)
#' sd(log10(d)) # 1
#' logsd2cv(1) # 1413.21\%
#'
#' @author Felipe Figueiredo
#' @export

logsd2cv <- function(x) {
sqrt(exp((log(10)^2)*x^2) - 1)*100
}
16 changes: 16 additions & 0 deletions R/logvar2cv.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
#' Convert the log-transformed variance from a log-normal variable to the CV.
#'
#' @description
#'
#' @param x A numeric value, vector or list.
#'
#' @return Returns the geometric CV (as percentage)
#'
#' @examples
#' d <- c(10,100,1000)
#' var(log10(d)) # 1
#' logvar2cv(1) # 1413.21\%
#'
#' @author Felipe Figueiredo
#' @export

logvar2cv <- function(x) {
sqrt(exp((log(10)^2)*x) - 1)*100
}
20 changes: 20 additions & 0 deletions R/predint.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
#' Prediction Intervals for given data
#'
#' @description Compute a prediction interval of a vector, which is assumed
#' normally distributed with unknown mean and variance.
#'
#' @param datavector A numeric value, vector or list.
#' @param alpha the significance level required
#'
#' @return a vector of two values
#' A vector with values giving lower and upper prediction limits for each parameter.
#'
#' @examples
#' x <- rnorm(30)
#' predint(x)
#'
#' @author Felipe Figueiredo
#' @export
#' @importFrom stats sd
#' @importFrom stats qt

predint <- function(datavector, alpha = 0.05) {
datavector <- datavector[!is.na(datavector)] # discard NA values
N <- length(datavector)
Expand Down
Binary file modified inst/rmarkdown/templates/Relatorio/skeleton/misc/style.docx
Binary file not shown.
5 changes: 2 additions & 3 deletions inst/rmarkdown/templates/Relatorio/skeleton/skeleton.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ output:
fig_caption: yes
fig_height: 6
fig_width: 6
keep_md: yes
number_sections: yes
toc: yes
pdf_document:
Expand All @@ -18,7 +19,7 @@ output:
fig_width: 6
reference_docx: misc/style.docx
toc: yes
subtitle: 'CÓDIGO: analise_dados_XX_aaaa'
subtitle: 'RELATÓRIO: analise_dados_XX_aaaa'
toc-title: "Sumário"
---

Expand All @@ -29,8 +30,6 @@ options(scipen = 999)
library(pander)
library(knitr)
library(philsfmisc)


```

---
Expand Down
Loading