Skip to content

Commit

Permalink
review documentation 📝
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Cazelles committed Jun 21, 2019
1 parent 00fe13e commit 3bb4dd3
Show file tree
Hide file tree
Showing 59 changed files with 225 additions and 256 deletions.
6 changes: 3 additions & 3 deletions R/addURL.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#'
#' @param url A URL.
#' @param text A character string to be searched within.
#' @param extra Extra A connection object or a character string that stand for a path,
#' ignored if text is defined.
#' @param markdown logical. If \code{TRUE}, hyperlinks marks of Markdown language are sought.
#' @param extra Extra A connection object or a character string that stand for
#' a path, ignored if text is defined.
#' @param markdown logical. If `TRUE`, hyperlinks marks of Markdown language are sought.
#'
#' @export
#'
Expand Down
11 changes: 4 additions & 7 deletions R/addWebIcon.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
#'
#' Generates a HTML tag to include an icon from an iconic framework.
#'
#' @author
#' Kevin Cazelles
#'
#' @param name name of the icon to be added.
#' @param framework a character use to default is \code{fa} (which stands for Font-Awesome).
#' @param size default sets to \code{2},
#' @param framework a character use to default is `fa` (which stands for Font-Awesome).
#' @param size default sets to `2`,
#' @export
#'
#' @examples
#' addWebIcon('cc')

addWebIcon <- function(name, framework = "fa", size = 2) {
paste0("<i class=\"", framework, " ", framework, "-", name, " ", framework, "-",
size, "x\"></i>")
paste0("<i class=\"", framework, " ", framework, "-", name, " ",
framework, "-", size, "x\"></i>")
}
6 changes: 3 additions & 3 deletions R/adjustString.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' @param extra character vector, or a vector to be coerced to a character
#' vector that will be (partially) added to produced a string of
#' @param before logical. If `TRUE`, then the extra characters are added before
#' \code{x}
#' `x`
#'
#' @details
#' This function was originally created to help getting a fixed number of digits
Expand All @@ -30,7 +30,7 @@


adjustString <- function(x, szchar, extra = 0, before = TRUE) {
x %<>% as.character
x <- as.character(x)
szchar %<>% as.numeric %>% floor %>% abs
extra %<>% as.character %>% strsplit(split = "") %>% extract2(1)
##
Expand All @@ -39,7 +39,7 @@ adjustString <- function(x, szchar, extra = 0, before = TRUE) {
##
. <- "No note"
##
if (sum(id1) > 0) {
if (sum(id1)) {
val <- szchar - nchar(x[id1])
out[id1] <- val %>% as.list %>% lapply(FUN = . %>% rep(extra, length.out = .) %>%
paste(collapse = "")) %>% unlist
Expand Down
14 changes: 6 additions & 8 deletions R/aggregateCol.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
#' Aggregate columns
#'
#' The \code{aggregateCol} function eases the computation of a given function on
#' a specific subset of columns.
#' `aggregateCol()` perform summary statistics on a specific subset of columns.
#'
#' @author
#' Kevin Cazelles
#'
#' @param data a data frame.
#' @param grp an integer vector assigning a group to every column of `data`
#' used to compute operations on a subset of columns. Any integer is a valid group,
#' `0` indicates that the column must be unchanged, `NA` is used to remove
#' columns.
#' used to compute operations on a subset of columns. Any integer is a valid
#" group, `0` indicates that the column must be unchanged, `NA` removes columns.
#' @param FUN a function to be applied to all group of columns.
#' @param names_aggreg column names for aggregated columns.
#' @param ... further arguments to be passed to \code{FUN}.
#' @param ... further arguments to be passed to `FUN`.
#'
#' @details
#' An integer vector, whose length is the number of
#' columns of the input data frame, is used to assign a group to each column
#' that explicits the subsetting. Furthermore columns can be either kept as is
#' using \code{0} or discarded by using \code{NA}.
#' that explicit the subsetting. Furthermore columns can be either kept as is
#' using `0` or discarded by using `NA`.
#'
#' @seealso [stats::aggregate()]
#'
Expand Down
21 changes: 10 additions & 11 deletions R/assignClass2df.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#' Assign a class to a set of column of a data frame
#' Assign a class to columns
#'
#' This function is designed to ease the changes of column's class
#' of a given data frame.
#' Assign a class to a set of column of a data frame. This function is designed
#' to ease the changes of column's class of a given data frame.
#'
#' @param x a data frame or a R object to be coerced into a data frame.
#' @param colid the identity of columns for which class are ti be changed.
#' @param cls a character vector containing the classes' names to be used in the
#' same order as colid. By default \code{cls} is repeated until its size equals
#' \code{colid}'s size.
#' same order as `colid`. By default `cls` is repeated until its size equals
#' `colid`'s size.
#'
#' @return
#' A data.frame for which columns have the required classes.
#'
#' @importFrom magrittr %<>%
#' @export
#' @examples
#' df1 <- matrix(signif(runif(20),4), ncol=2)
Expand All @@ -22,14 +21,14 @@


assignClass2df <- function(x, colid, cls) {
##
x %<>% as.data.frame
##
x <- as.data.frame(x)
stopifnot(colid %in% 1:ncol(x))
out <- x
sz <- length(colid)
cl <- rep(cls, length.out = sz)
##
##
for (i in 1:sz) out[, colid[i]] <- methods::as(x[, colid[i]], cl[i])
##
return(out)
##
out
}
13 changes: 6 additions & 7 deletions R/assignIds.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
#' Assign an id to a list of characters or factors
#'
#' This function is done mainly to assign an id to factor or similar character
#' strings. Regarding factors, \code{as.integer} does such task
#' but the order obtained could be different.
#' This function aims to assign an id to factor or similar character
#' strings. Regarding factors, [as.integer()] does such task but the order
#' obtained may differ
#'
#' @param x an R object to be coerced into character type.
#' @param alphabetical a logical indicating whether an alphabetical sorting must be applied.
#' @param alphabetical a logical indicating whether an alphabetical sorting
#' must be applied.
#' @return
#' A vector of Ids.
#' @importFrom magrittr %>%
#' @importFrom magrittr %<>%
#' @export
#' @examples
#' assignIds(list(2,'f', 'd', 'f'))


assignIds <- function(x, alphabetical = FALSE) {
tmp <- x %>% as.character %>% unique
if (alphabetical)
tmp %<>% sort
tmp <- sort(tmp)
out <- tmp %>% length %>% integer
for (i in 1:length(tmp)) out[x == tmp[i]] <- i
out
Expand Down
2 changes: 0 additions & 2 deletions R/categorize.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#' Assigns a category to each element of a vector for a given set of threshold
#' values..
#'
#' @author
#' Kevin Cazelles
#' @param x A numeric, complex, character or logical vector.
#' @param categ A set of threshold values used to assign categories.
#' @param lower A logical, if `TRUE` threshold values (i.e. values within
Expand Down
10 changes: 4 additions & 6 deletions R/dfTemplate.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#' Create a data frame from scratch or based on one or two data frames.
#'
#' This function handles the creation of data frames based on intuitive parameters.
#' It was originally designed to make row binding easier when columns differs
#' among data frame by creating data frames with the same columns.
#'
#' @author
#' Kevin Cazelles
#' This function handles the creation of data frames based on intuitive
#' parameters. It was originally designed to make row binding easier when
#' columns differs among data frame by creating data frames with the same
#' columns.
#'
#' @param cols either a number of column or a vector of character used as
#' columns names of the data frame to be returned.
Expand Down
9 changes: 4 additions & 5 deletions R/duplicateRow.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
#' @param x a data.frame.
#' @param id.el identity of the elements to be duplicated.
#' @param times number of times elements are duplicated. Could be a vector of the same length as id.el.
#' @param append A logical. If \code{TRUE}, duplicated elements will be appended to the dataframe otherwise duplicated elements remain next to their parent. Non-existing columns cannot be duplicated while non-existing rows can and produce \code{NA}.
#'
#' @importFrom magrittr %>% %<>%
#' @param append A logical. If `TRUE`, duplicated elements will be appended to the dataframe otherwise duplicated elements remain next to their parent. Non-existing columns cannot be duplicated while non-existing rows can and produce `NA`.
#' @importFrom magrittr %>%
#' @export
#' @examples
#' data(iris, package='datasets')
Expand All @@ -24,7 +23,7 @@ duplicateRow <- function(x, id.el = 1, times = 1, append = FALSE) {
if (class(pos) == "character")
ord <- c(rownames(x), pos) else ord <- c(1:nrow(x), pos)
if (!append)
ord %<>% sort
ord <- sort(ord)

x[ord, ]
}
Expand All @@ -37,7 +36,7 @@ duplicateCol <- function(x, id.el = 1, times = 1, append = FALSE) {
if (class(pos) == "character")
ord <- c(colnames(x), pos) else ord <- c(1:ncol(x), pos)
if (!append)
ord %<>% sort
ord <- sort(ord)

x[, ord]
}
15 changes: 7 additions & 8 deletions R/findRef.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#'
#' @param text A character string to be searched within.
#' @param con A connection object or a character string that stand for a path,
#' ignored if \code{text} is used.
#' @param markdown logical. If \code{TRUE}, citation tags of Markdown langage are sought.
#' ignored if `text` is used.
#' @param markdown logical. If `TRUE`, citation tags of Markdown langage are sought.
#'
#' @author
#' Kevin Cazelles
#'
#' @return
#' A dataframe with the citation keys and their frequence.
#' A data.frame with the citation keys and their frequence.
#' @export
#' @examples
#' test <- findRef(text='First \\cite{Pimm2000}, second \\Citep{May1972}')
Expand All @@ -20,22 +20,21 @@
findRef <- function(text, con, markdown = FALSE) {
##---
if (missing(text)) {
if (missing(con))
if (missing(con))
stop("Either 'text' or 'con' must be specified.") else {
lsfile <- readLines(con)
text <- paste(unlist(lsfile), collapse = "")
}
}
## ----
if (!markdown)
if (!markdown)
pat <- "[\\].{0,3}[cC]ite.{0,7}\\{[[:alnum:]]+}" else pat <- "@[[:alnum:]]+"
tbref <- multiMatch(text = text, pattern = pat)
## ----
if (markdown)
if (markdown)
tbref <- table(sub("@", "", tbref)) else {
tbref <- sub("[\\].{0,3}[cC]ite.{0,7}\\{", "", tbref)
tbref <- table(sub("\\}", "", tbref))
}
tbref <- data.frame(key = names(tbref), freq = as.integer(tbref))
tbref
data.frame(key = names(tbref), freq = as.integer(tbref))
}
6 changes: 3 additions & 3 deletions R/findReplace.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @author
#' Kevin Cazelles
#'
#' @param vec a vector where to search for patterns.
#' @param vec a vector to be searched.
#' @param vec_pat vector providing the patterns to be searched for.
#' @param y values to replace matching values.
#'
Expand All @@ -26,7 +26,7 @@

findReplace <- function(vec, vec_pat, y) {
vec[vec %in% vec_pat] <- y
return(vec)
vec
}


Expand All @@ -36,5 +36,5 @@ grepReplace <- function(vec, vec_pat, y) {
res <- lapply(vec_pat, function(x) grepl(vec, pattern = x))
res2 <- do.call(cbind, res) %>% apply(1L, sum)
vec[res2 > 0] <- y
return(vec)
vec
}
21 changes: 8 additions & 13 deletions R/findThem.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
#' Find values in a given vector.
#'
#' Given a set of values and a vector where the values must be found, the
#' \code{findThem} function records the matched values and the position in the
#' `findThem` function records the matched values and the position in the
#' vector where the values have been searched for.
#'
#' @author
#' Kevin Cazelles
#' @param what a vector a values to be searched for.
#' @param where a vector where values will be searched on.
#' @param todf a logical indicating whether the output object must be a data frame.
#' @param reportnomatch a logical. If TRUE, values without match are reported in
#' the data frame with a NA. Only available if \code{todf} is TRUE. Default is
#' set to FALSE.
#' @param reportnomatch a logical. If `TRUE`, values without match are reported #' in the data frame with a NA. Only available if `todf` is `TRUE`. Default is
#' set to `FALSE`.
#' @return
#' A list indicating matched positions for each elements of \code{what}. If no
#' match is found then \code{NA} is returned. If \code{todf} is TRUE
#' A list indicating matched positions for each elements of `what`. If no
#' match is found then `NA` is returned. If `todf` is `TRUE`
#' then a three-columns data frame is returned including values and positions
#' in both \code{what} and \code{where} vectors.
#' in both `what` and `where` vectors.
#' @seealso \code{\link[base]{which}}
#' @export
#' @examples
Expand Down Expand Up @@ -44,11 +43,7 @@ findThem <- function(what, where, todf = FALSE, reportnomatch = FALSE) {
out <- data.frame(values = rep(names(tmp), sz), what = rep(1:length(what),
sz), where = unlist(tmp))
rownames(out) <- NULL
} else {
out <- tmp
}
} else {
out <- NA_integer_
}
} else out <- tmp
} else out <- NA_integer_
out
}
8 changes: 4 additions & 4 deletions R/gaussianShape.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#' Flexible bell-shaped function.
#' Flexible bell-shaped function
#'
#' The \code{gaussianShape} function computes a personalizable Gaussian function.
#' Default values are the same as in \code{\link[stats]{dnorm}}.
#' The `gaussianShape()` function computes a personnalisable Gaussian function.
#' Default values are the same as in [stats::dnorm()].
#' @author
#' Kevin Cazelles
#' @param x a numeric vector.
#' @param optx x-values at which the maximum is reached.
#' @param opty extremum value.
#' @param width the width of the bell.
#' @param width width of the bell.
#' @param pow a real number.
#' @return
#' A vector containing values standing for categories into which elements of x have fallen.
Expand Down
3 changes: 1 addition & 2 deletions R/getDigits.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
#' @param x a character vector where digits are sought, or an object which can be coerced by `as.character` to a character vector.
#' @param collapse an optional character string to separate the results (see [base::paste()).
#'
#' @importFrom magrittr %>% %<>%
#' @importFrom magrittr %>%
#' @export
#'
#' @return
#' A list of digits.
#'
#'
#' @examples
#' getDigits('txt012-34')

Expand Down
12 changes: 7 additions & 5 deletions R/keepWords.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#' Keep these words.
#'
#' Extract words based on their position in a character string, vectorised over \code{string}.
#' Extract words based on their position in a character string, vectorised over
#' `string`.
#'
#' @author
#' Kevin Cazelles
#'
#' @param string Input vector. A character vector or list from which words will be extracted.
#' @param string An input character vector or a list from which words will be
#' extracted.
#' @param slc Vector of integer indicating the selected positions of the words to be kept.
#' @param punct.rm A logical indicating whether punctuation characters should be removed.
#' @param na.rm A logical indicating whether missing values should be removed.
#' @param collapse An optional character string used to separate selected words. Not \code{NA_character_}.
#' @param punct.rm A logical Should punctuation characters be removed?
#' @param na.rm A logical. Should missing values be removed?
#' @param collapse An optional character string used to separate selected words.
#'
#' @return A vector of the selected words concatenated for each string.
#' @importFrom magrittr %>%
Expand Down
Loading

0 comments on commit 3bb4dd3

Please sign in to comment.