rapport  an R templating system


Package functions

rapport is shipped with a bunch of (hopefully) handy functions to help you with generating reports and writing templates.

A detailed documentation based on up-to-date Rd files is also available below. Of course, you could check out the manual of the stable package in PDF format on CRAN too.

Datasets

ius2008: Internet Usage Survey
Description:

This dataset contains data gathered in a survey of Internet usage in Serbian population in the period from April to May 2008. During 90-day period, there were gathered 709 valid responses via on-line distributed questionnaire.

Details:

However, this dataset does not contain the original data, as some random noise is added afterwards, in order to demonstrate functionality of rapport helpers.

Dataset variables can be divided into 3 sets: demographic data , Internet usage aspects and application usage/content preference .

Demographic variables

Internet usage aspects

Following variables depict various aspects of Internet usage:

Application usage and on-line content preference

These variables include data on the use of Internet applications and content available on the Internet. Practically, they contain responses from a set of 8 questions on a five-point Likert scale.

Examples:
rapport("example", ius2008, var = "it.leisure")

Generic graph functions

rp.barplot: Barplot
Description:

This function is a wrapper around barchart which operates only on factors with optional facet.

Usage:
rp.barplot(x, facet = NULL, data = NULL, groups = FALSE,    percent = FALSE, horizontal = TRUE, ...)
Arguments:
x

a numeric variable

facet

an optional categorical variable to make facets by

data

an optional data frame from which the variables should be taken

groups

see xyplot

percent

an option to show percentages (100 category) instead of number of cases. Handy with groups=TRUE . Default value: FALSE without groups, TRUE with groups.

horizontal

see xyplot

...

additional parameters to barchart

Examples:
rp.barplot(ius2008$game)
rp.barplot(ius2008$game, horizontal = FALSE)
rp.barplot(ius2008$game, facet = ius2008$gender)
rp.barplot(ius2008$game, facet = ius2008$dwell, horizontal = FALSE, layout = c(1,3))
rp.barplot(ius2008$game, facet = ius2008$gender, groups = TRUE)
with(ius2008, rp.barplot(game, facet = gender))
rp.barplot(gender, data = ius2008)
rp.barplot(dwell, gender, ius2008)

rp.boxplot: Boxplot
Description:

This function is a wrapper around bwplot which operates only on numeric variables with optional facet.

Usage:
rp.boxplot(x, y = NULL, facet = NULL, data = NULL, ...)
Arguments:
x

a factor variable

y

a numeric variable

facet

an optional categorical variable to make facets by

data

an optional data frame from which the variables should be taken

...

additional parameters to bwplot

Examples:
rp.boxplot(ius2008$age)
rp.boxplot(ius2008$age, ius2008$gender)
rp.boxplot(ius2008$age, ius2008$dwell, facet = ius2008$gender)
with(ius2008, rp.scatterplot(age, dwell, facet = gender))
rp.boxplot(age, dwell, data = ius2008)
rp.boxplot(age, dwell, gender, ius2008)

rp.densityplot: Density plot
Description:

This function is a wrapper around densityplot which operates only on numeric vectors with optional facet.

Usage:
rp.densityplot(x, facet = NULL, data = NULL, ...)
Arguments:
x

a numeric variable

facet

an optional categorical variable to make facets by

data

an optional data frame from which the variables should be taken

...

additional parameters to densityplot

Examples:
rp.densityplot(ius2008$edu)
rp.densityplot(ius2008$edu, facet = ius2008$gender)
rp.densityplot(ius2008$edu, ius2008$dwell)
with(ius2008, rp.densityplot(edu, facet = gender))
rp.densityplot(edu, data = ius2008)
rp.densityplot(edu, gender, ius2008)

rp.dotplot: Dotplot
Description:

This function is a wrapper around dotplot which operates only on factors with optional facet.

Usage:
rp.dotplot(x, facet = NULL, data = NULL, groups = FALSE,    horizontal = TRUE, ...)
Arguments:
x

a factor variable

facet

an optional categorical variable to make facets by

data

an optional data frame from which the variables should be taken

groups

see xyplot

horizontal

see xyplot

...

additional parameters to dotplot

Examples:
rp.dotplot(ius2008$game)
rp.dotplot(ius2008$game, horizontal = FALSE)
rp.dotplot(ius2008$game, facet = ius2008$dwell)
rp.dotplot(ius2008$dwell, facet = ius2008$gender, horizontal = FALSE)
rp.dotplot(ius2008$game, facet = ius2008$dwell, groups = TRUE)
with(ius2008, rp.dotplot(gender, facet = dwell))
rp.dotplot(game, data = ius2008)
rp.dotplot(dwell, gender, ius2008)

rp.graph.check: Input cheks (internal)
Description:

Internal function used by eg. rp.histogram .

Usage:
rp.graph.check(x, facet = NULL, subset = NULL, ...)
Arguments:
x

a variable

facet

if facet set

subset

if subset set

...

other parameters

rp.hist: Histogram
Description:

This function is a wrapper around histogram which operates only on numeric vectors with optional facet.

Usage:
rp.hist(x, facet = NULL, data = NULL,    kernel.smooth = FALSE, ...)
Arguments:
x

a numeric variable

facet

an optional categorical variable to make facets by

data

an optional data frame from which the variables should be taken

kernel.smooth

add kernel density plot?

...

additional parameters to histogram

Examples:
rp.hist(ius2008$edu)
rp.hist(ius2008$edu, facet=ius2008$gender)
rp.hist(ius2008$edu, ius2008$dwell)
rp.hist(ius2008$edu, kernel.smooth=TRUE)
with(ius2008, rp.hist(edu, facet = gender))
rp.hist(edu, data = ius2008)
rp.hist(edu, gender, ius2008)

rp.lineplot: Lineplot
Description:

This function is a wrapper around xyplot with custom panel. Only numeric variables are accepted with optional facet.

Usage:
rp.lineplot(x, y, facet = NULL, data = NULL,    groups = NULL, ...)
Arguments:
x

a numeric variable

y

a numeric variable

facet

an optional categorical variable to make facets by

groups

an optional categorical grouping variable

data

an optional data frame from which the variables should be taken

...

additional parameters to xyplot

Examples:
a <- aggregate(wt~gear, mtcars, mean)
rp.lineplot(a$gear, a$wt)
rp.lineplot(gear, wt, data=a)
## lame demo:
rp.lineplot(1:length(mtcars$hp), mtcars$hp, facet=mtcars$cyl)
## advanced usage
rp.lineplot(partner, age, data = rp.desc('age', 'partner', fn = 'mean', data=ius2008)) ## TODO: fix....
rp.lineplot(partner, age, gender, data = rp.desc('age', c('gender', 'partner'), fn = 'mean', data=ius2008))
rp.lineplot(partner, age, groups = gender, data=rp.desc('age', c('gender', 'partner'), fn = 'mean', data = ius2008))
## Did you noticed the nasty axis titles? Why not correct those? :)
df <- rp.desc('age', 'partner', fn = 'mean', data = ius2008)
lapply(names(df), function(x) rp.label(df[, x]) <<- x)   # nasty solution!
rp.lineplot(partner, age, data = df)
df <- rp.desc('age', c('gender', 'partner'), fn = 'mean', data = ius2008)
lapply(names(df), function(x) rp.label(df[, x]) <<- x)  # nasty solution!
rp.lineplot(partner, age, gender, data = df)
df <- rp.desc('age', c('gender', 'partner'), fn = 'mean', data = ius2008)
lapply(names(df), function(x) rp.label(df[, x]) <<- x)  # nasty solution!
rp.lineplot(partner, age, groups = gender, data = df)

rp.qqplot: Q-Q plot with Theoretical Distribution
Description:

This function is a wrapper around qqmath which operates only on a numeric variable with optional facet.

Usage:
rp.qqplot(x, dist = qnorm, facet = NULL, data = NULL,    ...)
Arguments:
x

a numeric variable

dist

a theoretical distribution

facet

an optional categorical variable to make facets by

data

an optional data frame from which the variables should be taken

...

additional parameters to qqmath

Examples:
rp.qqplot(ius2008$age)
rp.qqplot(ius2008$age, qunif)
rp.qqplot(ius2008$age, qunif, facet = ius2008$gender)
with(ius2008, rp.qqplot(age))
rp.qqplot(age, data = ius2008)
rp.qqplot(age, facet = gender, data = ius2008)
rp.qqplot(age, qunif, gender, ius2008)
rp.qqplot(ius2008$age, panel = function(x) {panel.qqmath(x); panel.qqmathline(x, distribution = qnorm)} )

rp.scatterplot: Scatterplot
Description:

This function is a wrapper around xyplot which operates only on numeric variables with optional facet.

Usage:
rp.scatterplot(x, y, facet = NULL, data = NULL, ...)
Arguments:
x

a numeric variable

y

a numeric variable

facet

an optional categorical variable to make facets by

data

an optional data frame from which the variables should be taken

...

additional parameters to xyplot

Examples:
rp.scatterplot(ius2008$edu, ius2008$age)
rp.scatterplot(ius2008$edu, ius2008$age, facet=ius2008$gender)
with(ius2008, rp.scatterplot(edu, age, facet = gender))
rp.scatterplot(edu, age, data=ius2008)
rp.scatterplot(edu, age, gender, ius2008)

Generic helper functions

adj.rle: Adjacent Values Run Length Encoding
Description:

Similar to rle function, this function detects "runs" of adjacent integers, and displays vector of run lengths and list of corresponding integer sequences.

Usage:
adj.rle(x)
Arguments:
x

a numeric vector with

Returned value:

a list with two elements: vector of run lengths, and another list of values corresponding to generated sequences' lengths.

References:

See original thread for more details http://stackoverflow.com/a/8467446/457898 . Special thanks to Gabor Grothendieck for this one!

alike.integer: Check integers
Description:

This function tests if given variable "appears" to be an integer. To qualify as such, two conditions need to be satisfied: it should be stored as numeric object, and it should pass regular expression test if it consists only of digits.

Usage:
alike.integer(x)
Arguments:
x

a numeric variable that is to be tested

Returned value:

a logical value that indicates that tested variable "looks like" integer

capitalise: Capitalise String
Description:

Capitalises strings in provided character vector

Usage:
capitalise(x)
Arguments:
x

a character vector to capitalise

Returned value:

character vector with capitalised string elements

Examples:
capitalise(c("foo", "bar")) # [1] "Foo" "Bar"

catn: Concatenate with newline
Description:

A simple wrapper for cat function that appends newline to output.

Usage:
catn(...)
Arguments:
...

arguments to be passed to cat function

Returned value:

None (invisible NULL ).

is.boolean: Boolean
Description:

Checks if provided object is a boolean i.e. a length-one logical vector.

Usage:
is.boolean(x)
Arguments:
x

an object to check

Returned value:

a logical value indicating whether provided object is a boolean

Examples:
    is.boolean(TRUE)                # [1] TRUE
    # the following will work on most systems, unless you have tweaked global Rprofile
    is.boolean(T)                   # [1] TRUE
    is.boolean(1)                   # [1] FALSE
    is.string(c("foo", "bar"))      # [1] FALSE

is.empty: Empty Value
Description:

Rails-inspired helper that checks if vector values are "empty", i.e. if it's: NULL , zero-length, NA , NaN , FALSE , an empty string or 0 . Note that unlike its native R is.<something> sibling functions, is.empty is vectorised (hence the "values").

Usage:
is.empty(x, trim = TRUE, ...)
Arguments:
x

an object to check its emptiness

trim

trim whitespace? ( TRUE by default)

...

additional arguments for sapply

Examples:
is.empty(NULL)     # [1] TRUE
is.empty(c())      # [1] TRUE
is.empty(NA)       # [1] TRUE
is.empty(NaN)      # [1] TRUE
is.empty("")       # [1] TRUE
is.empty(0)        # [1] TRUE
is.empty(0.00)     # [1] TRUE
is.empty("    ")   # [1] TRUE
is.empty("foobar") # [1] FALSE
is.empty("    ", trim = FALSE)    # [1] FALSE
# is.empty is vectorised!
all(is.empty(rep("", 10)))        # [1] TRUE
all(is.empty(matrix(NA, 10, 10))) # [1] TRUE

is.exnull: Existed object with the value NULL
Description:

Checks if provided object exists but the value of that is NULL.

Usage:
is.exnull(x)
Arguments:
x

an object to check

Returned value:

a logical value indicating whether provided object exists but the value of that is NULL

Examples:
is.exnull(1)		  # [1] FALSE
is.exnull("")	  # [1] FALSE
is.exnull(NULL) 	# [1] TRUE

is.number: Numbers
Description:

Checks if provided object is a number, i.e. a length-one numeric vector.

Usage:
is.number(x, integer = FALSE)
Arguments:
x

an object to check

integer

logical: check if number is integer

Returned value:

a logical value indicating whether provided object is a string

Examples:
is.number(3)              # [1] TRUE
is.number(3:4)            # [1] FALSE
is.number("3")            # [1] FALSE
is.number(NaN)            # [1] TRUE
is.number(NA_integer_)    # [1] TRUE

is.string: Strings
Description:

Checks if provided object is a string i.e. a length-one character vector.

Usage:
is.string(x)
Arguments:
x

an object to check

Returned value:

a logical value indicating whether provided object is a string

Examples:
is.string("foobar")          # [1] TRUE
    is.string(1)                 # [1] FALSE
    is.string(c("foo", "bar"))   # [1] FALSE

messagef: Send Message with String Interpolated Messages
Description:

Combines warning with sprintf thus allowing string interpolated diagnostic messages.

Usage:
messagef(s, ...)
Arguments:
s

a character vector of format strings

...

values to be interpolated

Examples:
messagef("%.3f is not larger than %d and/or smaller than %d", pi, 10, 40)

stopf: Stop Execution with String Interpolated Messages
Description:

This helper combines stop function with sprintf thus allowing string interpolated messages when execution is halted.

Usage:
stopf(s, ...)
Arguments:
s

a character vector of format strings

...

values to be interpolated

Returned value:

a string containing message that follows execution termination

Examples:
stopf("%.3f is not larger than %d and/or smaller than %d", pi, 10, 40)

tocamel: CamelCase
Description:

Convert character vector to camelcase - capitalise first letter of each word.

Usage:
tocamel(x, delim = "[^[:alnum:]]", upper = FALSE,    sep = "", ...)
Arguments:
x

a character vector to be converted to camelcase

delim

a string containing regular expression word delimiter

upper

a logical value indicating if the first letter of the first word should be capitalised (defaults to FALSE )

sep

a string to separate words

...

additional arguments to be passed to strsplit

Returned value:

a character vector with strings put in camelcase

Examples:
tocamel("foo.bar")
    ## [1] "fooBar"
    tocamel("foo.bar", upper = TRUE)
    ## [1] "FooBar"
    tocamel(c("foobar", "foo.bar", "camel_case", "a.b.c.d"))
    ## [1] "foobar"    "fooBar"    "camelCase" "aBCD"

trim.space: Trim Spaces
Description:

Removes leading and/or trailing space(s) from a character vector. By default, it removes both leading and trailing spaces.

Usage:
trim.space(x,    what = c("both", "leading", "trailing", "none"),    space.regex = "[:space:]", ...)
Arguments:
x

a character vector which values need whitespace trimming

what

which part of the string should be trimmed. Defaults to both which removes trailing and leading spaces. If none , no trimming will be performed.

space.regex

a character value containing a regex that defines a space character

...

additional arguments for gsub function

Returned value:

a character vector with (hopefully) trimmed spaces

vgsub: Vectorised String Replacement
Description:

A simple wrapper for gsub that replaces all patterns from pattern argument with ones in replacement over vector provided in argument x .

Usage:
vgsub(pattern, replacement, x, ...)
Arguments:
pattern

see eponymous argument for gsub function

replacement

see eponymous argument for gsub function

x

see eponymous argument for gsub function

...

additional arguments for gsub function

Returned value:

a character vector with string replacements

References:

See original thread for more details http://stackoverflow.com/a/6954308/457898 . Special thanks to user Jean-Robert for this one!

warningf: Send Warning with String Interpolated Messages
Description:

Combines warning with sprintf thus allowing string interpolated warnings.

Usage:
warningf(s, ...)
Arguments:
s

a character vector of format strings

...

values to be interpolated

Examples:
warningf("%.3f is not larger than %d and/or smaller than %d", pi, 10, 40)

Generic helpers functions

is.tabular: Tabular Structure
Description:

Checks if object has "tabular" structure (not to confuse with table ) - in this particular case, that means matrix and data.frame objects only.

Usage:
is.tabular(x)
Arguments:
x

an object to be checked for "tabular" format

Returned value:

a logical value indicating that provided object has tabular structure

Examples:
is.tabular(HairEyeColor[, , 1])  # [1] TRUE
is.tabular(mtcars)               # [1] TRUE
is.tabular(table(mtcars$cyl))    # [1] FALSE
is.tabular(rnorm(100))           # [1] FALSE
is.tabular(LETTERS)              # [1] FALSE
is.tabular(pi)                   # [1] FALSE

is.variable: Variables
Description:

From rapport 's point of view, a variable is a non- NULL atomic vector that has no dimension attribute (see dim for details). This approach bypasses factor issues with is.vector , and also eliminates multidimensional vectors, such as matrices and arrays.

Usage:
is.variable(x)
Arguments:
x

an object to be checked for "variable" format

Returned value:

a logical value indicating that provided object is a "variable"

Examples:
is.variable(rnorm(100))  # [1] TRUE
is.variable(LETTERS)     # [1] TRUE
is.variable(NULL)        # [1] FALSE
is.variable(mtcars)      # [1] FALSE
is.variable(HairEyeColor[, , 1])  # [1] FALSE
is.variable(list())      # [1] FALSE

Generic stat functions

fml: Create Formula from Strings
Description:

Takes multiple character arguments as left and right-hand side arguments of a formula, and concatenates them in a single string.

Usage:
fml(left, right, join.left = " + ", join.right = " + ")
Arguments:
left

a string with left-hand side formula argument

right

a character vector with right-hand side formula arguments

join.left

concatenation string for elements of character vector specified in left

join.right

concatenation string for elements of character vector specified in right

Examples:
fml("hp", c("am", "cyl"))    # "hp ~ am + cyl"

pct: Percent
Description:

Appends a percent sign to provided numerical value. Rounding is carried out according to value passed in decimals formal argument (defaults to value specified in panderOptions('digits') ).

Usage:
pct(x, digits = panderOptions("digits"),    type = c("percent", "%", "proportion"),    check.value = TRUE)
Arguments:
x

a numeric value that is to be rendered to percent

digits

an integer value indicating number of decimal places

type

a character value indicating whether percent or proportion value was provided (partial match is allowed)

check.value

perform a sanity check to see if provided numeric value is correct (defaults to TRUE )

Returned value:

a character value with formatted percent

rp.desc: Descriptive Statistics
Description:

Aggregate table of descriptives according to functions provided in fn argument. This function follows melt/cast approach used in reshape package. Variable names specified in measure.vars argument are treated as measure.vars , while the ones in id.vars are treated as id.vars (see melt.data.frame for details). Other its formal arguments match with corresponding arguments for cast function. Some post-processing is done after reshaping, in order to get pretty row and column labels.

Usage:
rp.desc(measure.vars, id.vars = NULL, fn, data = NULL,    na.rm = TRUE, margins = NULL, subset = TRUE, fill = NA,    add.missing = FALSE, total.name = "Total",    varcol.name = "Variable",    use.labels = getOption("rp.use.labels"),    remove.duplicate = TRUE)
Arguments:
measure.vars

either a character vector with variable names from data , a numeric vector, or a data.frame

id.vars

same rules apply as in measure.vars , but defaults to NULL

fn

a list with functions or a character vector with function names

data

a data.frame holding variables specified in id.vars and measure.vars

na.rm

a logical value indicating whether NA values should be removed

margins

should margins be included? (see documentation for eponymous argument in melt.data.frame )

subset

a logical vector to subset the data before aggregating

fill

value to replace missing level combinations (see documentation for eponymous argument in melt.data.frame )

add.missing

show missing level combinations

total.name

a character string with name for "grand" margin (defaults to "Total")

varcol.name

character string for column that contains summarised variables (defaults to "Variable" )

use.labels

use labels instead of variable names in table header (handle with care, especially if you have lengthy labels). Defaults to value specified in rp.use.labels option.

remove.duplicate

should name/label of the variable provided in measure.vars be removed from each column if only one measure.var is provided (defaults to TRUE )

Returned value:

a data.frame with aggregated data

Examples:
rp.desc("cyl", "am", c(mean, sd), mtcars, margins = TRUE)
## c
rp.desc("age", c("gender", "student"), c("Average" = mean, "Deviation" = sd), ius2008, remove.duplicate = FALSE)

rp.freq: Frequency Table
Description:

Display frequency table with counts, percentage, and cumulatives.

Usage:
rp.freq(f.vars, data, na.rm = TRUE, include.na = FALSE,    drop.unused.levels = FALSE, count = TRUE, pct = TRUE,    cumul.count = TRUE, cumul.pct = TRUE,    total.name = "Total", reorder = FALSE)
Arguments:
f.vars

a character vector with variable names

data

a data.frame

na.rm

should missing values be removed?

include.na

should missing values be included in frequency table?

drop.unused.levels

should empty level combinations be left out

count

show frequencies?

pct

show percentage?

cumul.count

show cumulative frequencies?

cumul.pct

show cumulative percentage?

total.name

a sting containing footer label (defaults to "Total")

reorder

reorder the table based on frequencies?

Returned value:

a data.frame with a frequency table

Examples:
rp.freq(c("am", "cyl", "vs"), mtcars)

rp.iqr: Interquartile Range
Description:

Calculates interquartile range of given variable. See rp.univar for details.

Usage:
rp.iqr(...)
Arguments:
...

parameters to be passed to rp.univar function

Returned value:

a numeric value with variable's interquartile range

rp.kurtosis: Kurtosis
Description:

Calculates kurtosis of given variable. See rp.univar for details.

Usage:
rp.kurtosis(...)
Arguments:
...

parameters to be passed to rp.univar function

Returned value:

a numeric value with variable's kurtosis

rp.max: Maximum
Description:

Returns the maximum of all values in a vector by passing {codemax as fn argument to rp.univar function.

Usage:
rp.max(...)
Arguments:
...

parameters to be passed to rp.univar function

Returned value:

a numeric value with maximum value

rp.mean: Mean
Description:

Calculates mean of given variable by passing sum as fn argument to rp.univar function.

Usage:
rp.mean(...)
Arguments:
...

parameters to be passed to rp.univar function

Returned value:

a numeric value with variable's mean

rp.median: Median
Description:

Calculates median of given variable. See rp.univar for details.

Usage:
rp.median(...)
Arguments:
...

parameters to be passed to rp.univar function

Returned value:

a numeric value with variable's median

rp.min: Minimum
Description:

Returns the minimum of all values in a vector by passing {codemin as fn argument to rp.univar function.

Usage:
rp.min(...)
Arguments:
...

parameters to be passed to rp.univar function

Returned value:

a numeric value with minimum value

rp.missing: Missing Cases
Description:

Returns a number of missing ( NA ) values in a variable. This is a wrapper around rp.univar function with anonymous function passed to count number of NA elements in a variable.

Usage:
rp.missing(...)
Arguments:
...

parameters to be passed to rp.univar function

Returned value:

a numeric value with number of missing vector elements

rp.percent: Percent
Description:

Calculates percentage of cases for provided variable and criteria specified in subset argument. Function accepts numeric, factor and logical variables for x parameter. If numeric and/or factor is provided, subsetting can be achieved via subset argument. Depending on value of na.rm argument, either valid ( na.rm = TRUE ) or all cases ( na.rm = FALSE ) are taken into account. By passing logical variable to x , a sum of ( TRUE ) elements is calculated instead, and valid percents are used ( NA are excluded).

Usage:
rp.percent(x, subset = NULL, na.rm = TRUE, pct = FALSE,    ...)
Arguments:
x

a numeric variable to be summarised

subset

an expression that evaluates to logical vector (defaults to NULL )

na.rm

should missing values be

pct

print percent string too?

...

additional arguments for pct function

Returned value:

a numeric or string depending on the value of pct

Examples:
set.seed(0)
x <- sample(5, 100, replace = TRUE)
rp.percent(x > 2)

rp.range: Range
Description:

Calculates difference between the largest and the smallest value in a vector. See rp.univar for details.

Usage:
rp.range(...)
Arguments:
...

parameters to be passed to rp.univar function

Returned value:

a numeric value with calculated range

rp.sd: Standard Deviation
Description:

Calculates standard deviation of given variable. See rp.univar for details.

Usage:
rp.sd(...)
Arguments:
...

parameters to be passed to rp.univar function

Returned value:

a numeric value with variable's standard deviation

rp.se.mean: Standard Error of Mean
Description:

Calculates standard error of mean for given variable. See rp.univar for details.

Usage:
rp.se.mean(...)
Arguments:
...

parameters to be passed to rp.univar function

Returned value:

a numeric value with standard error of mean

rp.skewness: Skewness
Description:

Calculates skewness of given variable. See rp.univar for details.

Usage:
rp.skewness(...)
Arguments:
...

parameters to be passed to rp.univar function

Returned value:

a numeric value with variable's skewness

rp.sum: Sum
Description:

Returns the sum of variable's elements, by passing sum as fn argument to rp.univar function.

Usage:
rp.sum(...)
Arguments:
...

parameters to be passed to rp.univar function

Returned value:

a numeric value with sum of vector elements

rp.univar: Descriptive Statistics
Description:

This function operates only on vectors or their subsets, by calculating a descriptive statistic specified in fn argument.

Usage:
rp.univar(x, subset = NULL, fn, na.rm = TRUE, ...)
Arguments:
x

a numeric variable to be summarised

subset

an expression that evaluates to logical vector (defaults to NULL , in which case the function specified in fun is applied on a vector)

fn

a function or a function name to be applied on a variable or it's subset

na.rm

a logical value indicating whether NA 's should be removed (defaults to TRUE )

...

additional arguments for function specified in fn

Returned value:

a numeric

rp.valid: Valid Cases
Description:

Returns a number of valid (non- NA ) values in a variable. This is a wrapper around rp.univar function with length function passed in fn argument, but with missing values previously removed. However, it's not possible to cancel NA omission with this function (doing so will yield error).

Usage:
rp.valid(...)
Arguments:
...

parameters to be passed to rp.univar function

Returned value:

a numeric value with number of valid (non-NA) vector elements

rp.var: Variance
Description:

Calculates variance of given variable. See rp.univar for details.

Usage:
rp.var(...)
Arguments:
...

parameters to be passed to rp.univar function

Returned value:

a numeric value with variable's variance

Generic stat helper functions

htest: Hypothesis Tests
Description:

This function uses htest.short , to extract statistic and p-value from htest -classed object. Main advantage of using htest is that it's vectorised, and can accept multiple methods.

Details:

Default parameters are read from options :

Usage:
htest(x, ..., use.labels = getOption("rp.use.labels"),    use.method.names = TRUE,    colnames = c("Method", "Statistic", "p-value"))
Arguments:
x

arguments to be passed to function specified in test

...

additional arguments for function specified in test

use.labels

a logical value indicating whether variable labels should be placed in row names. If set to FALSE , output of deparse(substitute(x)) will be used.

use.method.names

use the string provided in method attribute of htest object

colnames

a character string containing column names

Returned value:

a data.frame with applied tests in rows, and their results (statistic and p-value) in columns

Examples:
library(nortest)
htest(rnorm(100), shapiro.test)
htest(rnorm(100), lillie.test, ad.test, shapiro.test)
htest(mtcars, lillie.test)
htest(mtcars, lillie.test, ad.test, shapiro.test)

htest.short: Extract Values from htest Objects
Description:

Extract value of statistic and its p-value from htest object.

Usage:
htest.short(x)
Arguments:
x

htest -class object

Returned value:

named numeric vector with the value of statistic and its p-value

Examples:
htest.short(shapiro.test(rnorm(100)))

kurtosis: Kurtosis
Description:

Calculates kurtosis coefficient for given variable (see is.variable ), matrix or a data.frame .

Usage:
kurtosis(x, na.rm = FALSE)
Arguments:
x

a variable , matrix or a data.frame

na.rm

should NA s be removed before computation?

References:

Tenjovic, L. (2000). Statistika u psihologiji - prirucnik. Centar za primenjenu psihologiju.

Examples:
set.seed(0)
x <- rnorm(100)
kurtosis(x)
kurtosis(matrix(x, 10))
kurtosis(mtcars)
rm(x)

lambda.test: Goodman and Kruskal's lambda
Description:

Computes Goodman and Kruskal's lambda for given table.

Usage:
lambda.test(table, direction = 0)
Arguments:
table

a table of two variables or a data.frame representation of the cross-table of the two variables without marginals

direction

numeric value of c(0, 1, 2) where 1 means the lambda value computed for row, 2 for columns and 0 for both

Returned value:

computed lambda value(s) for row/col of given table

References:
Examples:
## quick example
x <- data.frame(x = c(5, 4, 3), y = c(9, 8, 7), z = c(7, 11, 22), zz = c(1, 15, 8))
lambda.test(x)    # 0.1 and 0.18333
lambda.test(t(x)) # 0.18333 and 0.1
## historical data (see the references above: p. 744)
men.hair.color <- data.frame(
b1 = c(1768, 946, 115),
b2 = c(807, 1387, 438),
b3 = c(189, 746, 288),
b4 = c(47, 53, 16)
)
row.names(men.hair.color) <- paste0('a', 1:3)
lambda.test(men.hair.color)
lambda.test(t(men.hair.color))
## some examples on mtcars
lambda.test(table(mtcars$am, mtcars$gear))
lambda.test(table(mtcars$gear, mtcars$am))
lambda.test(table(mtcars$am, mtcars$gear), 1)
lambda.test(table(mtcars$am, mtcars$gear), 2)

rp.outlier: Outlier test
Description:

A simple test for outliers. This functions returns all extreme values (if any) found in the specified vector.

Usage:
rp.outlier(x)
Arguments:
x

a numeric vector of values

Returned value:

vector of outlier values

References:

Credit goes to PaulHurleyuk: http://stackoverflow.com/a/1444548/564164

Examples:
rp.outlier(mtcars$hp)
rp.outlier(c(rep(1,100), 200))
rp.outlier(c(rep(1,100), 200,201))

skewness: Skewness
Description:

Calculates skewness coefficient for given variable (see is.variable ), matrix or a data.frame .

Usage:
skewness(x, na.rm = FALSE)
Arguments:
x

a variable , matrix or a data.frame

na.rm

should NA s be removed before computation?

References:

Tenjovic, L. (2000). Statistika u psihologiji - prirucnik. Centar za primenjenu psihologiju.

Examples:
set.seed(0)
x <- rnorm(100)
skewness(x)
skewness(matrix(x, 10))
skewness(mtcars)
rm(x)

as.character.rp.inputs: Convert Inputs to Character
Description:

Converts template inputs to character vector with YAML strings.

Usage:
## S3 method for class 'rp.inputs' as.character(x, ...)
Arguments:
x

template inputs object

...

ignored

as.character.rp.meta: Convert Metadata to Character
Description:

Converts template metadata to character vector with YAML strings.

Usage:
## S3 method for class 'rp.meta' as.character(x, ...)
Arguments:
x

template metadata object

...

ignored

check.input.value.class: Check Input Value Class
Description:

Checks the class of an input value.

Usage:
check.input.value.class(value,    class = c("character", "complex", "factor", "integer", "logical", "numeric", "raw"),    input.name = NULL)
Arguments:
value

input value

class

input class (defaults to NULL )

input.name

input name (used in messages)

check.input.value: Check input value
Description:

A bit misleading title/function name - it validates input values, according to rules set in general input attributes ( length ) or class-specific ones ( nchar , nlevels or limit ).

Usage:
check.input.value(input, value = NULL,    attribute.name = c("length", "nchar", "nlevels", "limit"))
Arguments:
input

input item

value

input value, either template-defined, or set by the user

attribute.name

input attributes containing validation rules (defaults to length )

check.report.chunks: Check Report Chunks
Description:

Checks for warnings and errors in report chunks.

Usage:
check.report.chunks(rp,    what = c("errors", "warnings", "messages"))
Arguments:
rp

rapport object

what

what fields to check. defaults to all

check.tpl: Check template validity
Description:

Throw error

Usage:
check.tpl(txt, open.tag = get.tags("header.open"),    close.tag = get.tags("header.close"), ...)
Arguments:
txt

character vector with template contents

open.tag

opening tag regexp

close.tag

closing tag regexp

...

additional params for tag matching (see grep )

extract.meta: Extract Template Metadata
Description:

Check if template metadata field matches provided format, and return matched value in a list.

Usage:
extract.meta(x, title, regex, short = NULL,    trim.white = TRUE, mandatory = TRUE,    default.value = NULL, field.length = 1000, ...)
Arguments:
x

a string containing template metadata

title

a string containing metadata field title (can be regex-powered)

regex

a string with regular expression to match field value

short

a string with a short name for given metadata field

trim.white

a logical value indicating whether trailing and leading spaces of the given string should be removed before extraction

mandatory

a logical value indicating required field

default.value

fallback to this value if non-mandatory field is not found/malformed

field.length

maximum number of field characters (defaults to 1000)

...

additional parameters for grepl function

Returned value:

a list with matched content, or NULL if the field is not required

Examples:
    rapport:::extract.meta("Name: John Smith", "Name", "[[:alpha:]]+( [[:alpha:]]+)?")
    ## $name
    ## [1] "John Smith"
    rapport:::extract.meta("Name: John", "Name", "[[:alpha:]]+( [[:alpha:]]+)?")
    ## $name
    ## [1] "John"

get.tags: Tag Values
Description:

Returns report tag vales (usually regexes): either user-defined, or the default ones.

Details:

Default parameters are read from options :

Usage:
get.tags(tag.type = c("all", "header.open", "header.close", "comment.open", "comment.close"),    preset = c("user", "default"))
Arguments:
tag.type

a character value with tag value name

preset

a character value specifying which preset to return

Returned value:

either a list (default) or a character value with tag regexes

Examples:
get.tags()        # same as 'get.tags("all")'
get.tags("header.open")

guess.input.description: Input Description
Description:

Checks and returns input description.

Usage:
guess.input.description(description)
Arguments:
description

a character string containing input description

guess.input.label: Input Label
Description:

Checks and returns input label.

Usage:
guess.input.label(label)
Arguments:
label

a character string containing input label

guess.input.name: Input Name Validation
Description:

From v. 0.51 one or more characters that are not newline should do the trick. Note that white spaces will be trimmed from both ends in resulting string.

Usage:
guess.input.name(name)
Arguments:
name

a character value with input name

guess.input: Guess Input
Description:

Checks and returns valid input from YAML input definition.

Usage:
guess.input(input)
Arguments:
input

a named list containing input definition

guess.old.input.length: Deprecated input limits
Description:

Guess deprecated input length.

Usage:
guess.old.input.length(x, input.type)
Arguments:
x

a character string containing input length definition

input.type

a character string containing input type

guess.old.input.type: Check Type
Description:

Checks type of template input, based on provided sting. If input definition is syntactically correct, a list is returned, containing input type, size limits, and default value (for CSV options and boolean types only).

Usage:
guess.old.input.type(x)
Arguments:
x

a character string containing input definition

is.heading: Pandoc Heading
Description:

Checks if provided string is a valid ATX-style pandoc heading.

Usage:
is.heading(x)
Arguments:
x

a string to test for pandoc heading format

Returned value:

a logical value indicating the string is (not) a pandoc heading

is.rapport: Rapport Object
Description:

Checks if provided R object is of rapport class.

Usage:
is.rapport(x)
Arguments:
x

any R object to check

Returned value:

a logical value indicating whether provided object is a rapport object

is.rp.heading: Rapport Heading Element
Description:

Checks if provided R object is a rapport heading element.

Usage:
is.rp.heading(x)
Arguments:
x

any R object to check

Returned value:

a logical value indicating whether provided object is a rp.heading object

print.rapport: Prints rapport
Description:

Default print method for rapport class objects that shows evaluated report contents.

Usage:
## S3 method for class 'rapport' print(x, ...)
Arguments:
x

any "rapport" class object

...

ignored

Examples:
rapport('example', data = mtcars, var='hp')

print.rp.info: Print Template Header
Description:

Prints out the contents of template header (both metadata and inputs) in human-readable format, so you can get insight about the template requirements.

Usage:
## S3 method for class 'rp.info' print(x, ...)
Arguments:
x

object of class rp.header . See tpl.header for details.

...

ignored

print.rp.inputs: Print Template Inputs
Description:

Prints out the contents of template inputs in human-readable format.

Usage:
## S3 method for class 'rp.inputs' print(x, ...)
Arguments:
x

object of class rp.inputs . See tpl.inputs for details.

...

ignored

print.rp.meta: Print Template Metadata
Description:

Prints out the contents of template metadata in human-readable format.

Usage:
## S3 method for class 'rp.meta' print(x, ...)
Arguments:
x

object of class rp.meta . See tpl.meta for details.

...

ignored

purge.comments: Purge Comments
Description:

Remove comments from provided character vector.

Details:

Default parameters are read from options :

Usage:
purge.comments(x,    comment.open = get.tags("comment.open"),    comment.close = get.tags("comment.close"))
Arguments:
x

a character string to remove comments from

comment.open

a string containing opening tag

comment.close

a string containing closing tag

Returned value:

a string with removed pandoc comments

rapport.docx: Rapport to DOCX
Description:

This is a simple wrapper around rapport and tpl.export . Basically it works like rapport but the returned class is exported at one go.

Usage:
rapport.docx(...)
Arguments:
...

parameters passed directly to rapport

rapport.html: Rapport to HTML
Description:

This is a simple wrapper around rapport and tpl.export . Basically it works like rapport but the returned class is exported at one go.

Usage:
rapport.html(...)
Arguments:
...

parameters passed directly to rapport

rapport.odt: Rapport to ODT
Description:

This is a simple wrapper around rapport and tpl.export . Basically it works like rapport but the returned class is exported at one go.

Usage:
rapport.odt(...)
Arguments:
...

parameters passed directly to rapport

rapport.pdf: Rapport to PDF
Description:

This is a simple wrapper around rapport and tpl.export . Basically it works like rapport but the returned class is exported at one go.

Usage:
rapport.pdf(...)
Arguments:
...

parameters passed directly to rapport

rapport: Evaluate Template
Description:

This is the central function in the rapport package, and hence eponymous. In following lines we'll use rapport to denote the function, not the package. rapport requires a template file, while dataset ( data argument) can be optional, depending on the value of Data required field in template header. Template inputs are matched with ... argument, and should be provided in x = value format, where x matches input name and value , wait for it... input value! See tpl.inputs for more details on template inputs.

Details:

Default parameters are read from evalsOptions() and the following options :

Usage:
rapport(fp, data = NULL, ..., env = new.env(),    reproducible = FALSE, header.levels.offset = 0,    graph.output = evalsOptions("graph.output"),    file.name = getOption("rp.file.name"),    file.path = getOption("rp.file.path"),    graph.width = evalsOptions("width"),    graph.height = evalsOptions("height"),    graph.res = evalsOptions("res"),    graph.hi.res = evalsOptions("hi.res"),    graph.replay = evalsOptions("graph.recordplot"))
Arguments:
fp

a template file pointer (see tpl.find for details)

data

a data.frame to be used in template

...

matches template inputs in format 'key = "value"'

env

an environment where template commands be evaluated (defaults to new.env()

reproducible

a logical value indicating if the call and data should be stored in template object, thus making it reproducible (see tpl.rerun for details)

header.levels.offset

number added to header levels (handy when using nested templates)

file.name

set the file name of saved plots and exported documents. A simple character string might be provided where %N would be replaced by an auto-increment integer based on similar exported document's file name , %n an auto-increment integer based on similar (plot) file names (see: ?evalsOptions ), %T by the name of the template in action and %t by some uniqe random characters based on tempfile .

file.path

path of a directory where to store generated images and exported reports

graph.output

the required file format of saved plots (optional)

graph.width

the required width of saved plots (optional)

graph.height

the required height of saved plots (optional)

graph.res

the required nominal resolution in ppi of saved plots (optional)

graph.hi.res

logical value indicating if high resolution (1280x~1280) images would be also generated

graph.replay

logical value indicating if plots need to be recorded for later replay (eg. while print ing rapport objects in R console)

Returned value:

a list with rapport class.

Examples:
rapport('Example', ius2008, v = "leisure")
rapport('Descriptives', ius2008, var = "leisure")
## generating high resolution images also
rapport('Example', ius2008, v = "leisure", graph.hi.res = TRUE)
rapport.html('NormalityTest', ius2008, var = "leisure", graph.hi.res=T)
## generating only high resolution image
rapport('Example', ius2008, v = "leisure", graph.width = 1280, graph.height = 1280)
## nested templates cannot get custom setting, use custom rapport option:
options('graph.hi.res' = TRUE)
rapport('AnalyzeWizard.tpl', data=ius2008, variables=c('edu', 'game'))

rp.label: Get Variable Label
Description:

This function returns character value previously stored in variable's label attribute. If none found, and fallback argument is set to TRUE (default), the function returns object's name (retrieved by deparse(substitute(x)) ), otherwise NA is returned with a warning notice.

Usage:
rp.label(x, fallback = TRUE, simplify = TRUE)
Arguments:
x

an R object to extract labels from

fallback

a logical value indicating if labels should fallback to object name(s)

simplify

coerce results to a vector ( TRUE by default), otherwise, a list is returned

Returned value:

a character vector with variable's label(s)

Examples:
x <- rnorm(100)
rp.label(x)         # returns "x"
rp.label(x, FALSE)  # returns NA and issues a warning
rp.label(mtcars$hp) <- "Horsepower"
rp.label(mtcars)         # returns "Horsepower" instead of "hp"
rp.label(mtcars, FALSE)  # returns NA where no labels are found
rp.label(sleep, FALSE)   # returns NA for each variable and issues a warning

rp.label-set: Set Variable Label
Description:

This function sets a label to a variable, by storing a character string to its label attribute.

Usage:
rp.label(var) <- value
Arguments:
var

a variable (see is.variable for details)

value

a character value that is to be set as variable label

Examples:
rp.label(mtcars$mpg) <- "fuel consumption"
x <- rnorm(100); ( rp.label(x) <- "pseudo-random normal variable" )

rp.name: Variable Name
Description:

This function returns character value previously stored in variable's name attribute. If none found, the function defaults to object's name.

Usage:
rp.name(x)
Arguments:
x

an R (atomic or data.frame/list) object to extract names from

Returned value:

a character value with variable's label

Examples:
rp.name(mtcars$am)
x <- 1:10; rp.name(x)

tpl.body: Template Body
Description:

Returns contents of the template body.

Usage:
tpl.body(fp, htag = get.tags("header.close"), ...)
Arguments:
fp

a template file pointer (see tpl.find for details)

htag

a string with closing body tag

...

additional arguments to be passed to grep function

Returned value:

a character vector with template body contents

tpl.check: Check Template
Description:

Checks if the examples of given template can be run without any error.

Details:

If everything went fine and you get a list of success equals to TRUE values, otherwise success returns FALSE with additional message

Usage:
tpl.check(fp)
Arguments:
fp

a character vector containing template name (".tpl" extension is optional), file path or a text to be split by line breaks

Examples:
tpl.check('example')

tpl.example: Template Examples
Description:

Displays template examples defined in Example section. Handy to check out what template does and how does it look like once it's rendered. If multiple examples are available, and index argument is NULL , you will be prompted for input. If only one example is available in the header, user is not prompted for input action, and given template is evaluated automatically. At any time you can provide an integer vector with example indices to index argument, and specified examples will be evaluated without prompting, thus returning a list of rapport objects. Example output can be easily exported to various formats (HTML, ODT, etc.) - check out documentation for tpl.export for more info.

Usage:
tpl.example(fp, index = NULL, env = .GlobalEnv)
Arguments:
fp

a template file pointer (see tpl.find for details)

index

a numeric vector indicating the example index - meaningful only for templates with multiple examples. Accepts vector of integers to match IDs of template example. Using 'all' (character string) as index will return all examples.

env

an environment where example will be evaluated (defaults to .GlobalEnv )

Examples:
tpl.example('Example')
tpl.example('Example', 1:2)
tpl.example('Example', 'all')
tpl.example('Crosstable')
tpl.export(tpl.example('Crosstable'))

tpl.export: Export rapport object
Description:

This function exports rapport class objects to various formats based on ascii package.

Details:

By default this function tries to export the report to HTML with pandoc. Some default styles are applied. If you do not like those default settings, use your own options .

Default parameters are read from options :

Please be sure to set 'tpl.user' option with options() to get your name in the head of your generated reports!

Usage:
tpl.export(rp = NULL, file, append = FALSE,    create = TRUE, open = TRUE,    date = pander.return(Sys.time()), description = TRUE,    format = "html", options = "", logo = TRUE)
Arguments:
rp

a rapport class object or list of rapport class objects

file

filename of the generated document. Inherited from rapport class if not set. If file is set with path (not equal to getwd() ), please set an absolute path for images (see: evalsOptions() ).

append

FALSE (new report created) or an R object (class of "Report") to which the new report will be added

create

should export really happen? It might be handy if you want to append several reports.

open

open the exported document? Default set to TRUE.

date

character string as the date field of the report. If not set, current time will be set.

description

add Description of the rapport class (template)? Default set to TRUE.

format

format of the wanted report. See Pandoc's user manual for details. In short, choose something like: html , pdf , odt or docx .

options

options passed to Pandoc.convert .

logo

add rapport logo

Returned value:

filepath on create = TRUE , Report class otherwise

References:

John MacFarlane (2012): _Pandoc User's Guide_. http://johnmacfarlane.net/pandoc/README.html

Examples:
## eval some template
x <- rapport('example', data = mtcars, var="hp")
## try basic parameters
tpl.export(x)
tpl.export(x, file='demo')
tpl.export(x, file='demo', format='odt')
### append reports
# 1) Create a report object with the first report and do not export (optional)
report <- tpl.export(x, create=F)
# 2) Append some other reports without exporting (optional)
report <- tpl.export(x, create=F, append=report)
# 3) Export it!
tpl.export(append=report)
# 4) Export it to other formats too! (optional)
tpl.export(append=report, format='rst')
### exporting multiple reports at once
tpl.export(tpl.example('example', 'all'))
tpl.export(tpl.example('example', 'all'), format='odt')
tpl.export(list(rapport('univar-descriptive', data = mtcars, var="hp"),
    rapport('univar-descriptive', data = mtcars, var="mpg")))
### Never do this as being dumb:
tpl.export()
### Using other backends
## asciidoc
tpl.export(tpl.example('example', 'all'), backend='asciidoc')
## txt2tags
tpl.export(tpl.example('example', 'all'), backend='t2t')
### Adding own custom CSS to exported HTML
tpl.export(x, options=sprintf('-c %s', system.file('templates/css/default.css', package='rapport')))

tpl.find: Read Template
Description:

Reads file either from template name in system folder, file path or remote URL, and splits it into lines for easier handling by rapport internal parser. "find" in tpl.find is borrowed from Emacs parlance - this function actually reads the template.

Usage:
tpl.find(fp, ...)
Arguments:
fp

a character string containing a template path, a template name (for package-bundled templates only), template contents separated by newline ( \n ), or a character vector with template contents.

...

additional params for header tag matching (see grep )

Returned value:

a character vector with template contents

tpl.header: Template Header
Description:

Returns rapport template header from provided path or a character vector.

Usage:
tpl.header(fp, open.tag = get.tags("header.open"),    close.tag = get.tags("header.close"), ...)
Arguments:
fp

a template file pointer (see tpl.find for details)

open.tag

a string with opening tag (defaults to value of user-defined "header.open" tag)

close.tag

a string with closing tag (defaults to value of user-defined "header.close" tag)

...

additional arguments to be passed to grep function

Returned value:

a character vector with template header contents

tpl.info: Template Info
Description:

Provides information about template metadata and/or inputs. See tpl.meta and tpl.inputs for details.

Usage:
tpl.info(fp, meta = TRUE, inputs = TRUE)
Arguments:
fp

a template file pointer (see tpl.find for details)

meta

return template metadata? (defaults to TRUE )

inputs

return template inputs? (defaults to TRUE )

Examples:
tpl.info('Example')  # return both metadata and inputs
tpl.info('Crosstable', inputs = FALSE)  # return only template metadata
tpl.info('Correlation', meta = FALSE)  # return only template inputs

tpl.inputs: Template Inputs
Description:

Displays summary for template inputs (if any). Note that as of version 0.5 , rapport template inputs should be defined using YAML syntax. See deprecated-inputs for details on old input syntax. The following sections describe new YAML input definition style.

Details:

Introduction

The full power of rapport comes into play with template inputs . One can match inputs against dataset variables or custom R objects. The inputs provide means of assigning R objects to symbol s in the template evaluation environment. Inputs themselves do not handle only the template names, but also provide an extensive set of rules that each dataset variable/user-provided R object has to satisfy. The new YAML input specification takes advantage of R class system. The input attributes should resemble common R object attributes and methods.

Inputs can be divided into two categories:

General input attributes

Following attributes are available for all inputs:

Class-specific attributes

character

numeric , integer

factor

Usage:
tpl.inputs(fp, use.header = FALSE)
Arguments:
fp

a template file pointer (see tpl.find for details)

use.header

a logical value indicating whether the header section is provided in h argument

tpl.list: Package Templates
Description:

Lists all templates bundled with current package build. By default, it will search for all .tpl files in current directory, path specified in tpl.paths option and package library path.

Usage:
tpl.list(...)
Arguments:
...

additional parameters for dir function

Returned value:

a character vector with template files

tpl.meta: Header Metadata
Description:

Displays summary of template metadata stored in a header section. This part of template header consists of several YAML key: value pairs, which contain some basic information about the template, just much like the DESCRIPTION file in R packages does.

Details:

Current implementation supports following fields:

As of version 0.5 , dataRequired field is deprecated. rapport function will automatically detect if the template requires a dataset based on the presence of standalone inputs.

Usage:
tpl.meta(fp, fields = NULL, use.header = FALSE,    trim.white = TRUE)
Arguments:
fp

a template file pointer (see tpl.find for details)

fields

a list of named lists containing key-value pairs of field titles and corresponding regexes

use.header

a logical value indicating if the character vector provided in fp argument contains only the header data (not the whole template)

trim.white

a logical value indicating if the extra spaces should removed from header fields before extraction

Returned value:

a named list with template metadata

tpl.paths.add: Add Template Path
Description:

Adds a new element to custom paths' list where rapport will look for templates.

Usage:
tpl.paths.add(...)
Arguments:
...

character vector of paths

Returned value:

TRUE on success (invisibly)

Examples:
tpl.paths.add('/tmp')
tpl.list()
## might trigger an error:
tpl.paths.add('/home', '/rapport')

tpl.paths: Template Paths
Description:

List all custom paths where rapport will look for templates.

Usage:
tpl.paths()
Returned value:

a character vector with paths

Examples:
tpl.paths()

tpl.paths.remove: Remove Template Path
Description:

Removes an element from custom paths' list where rapport will look for templates.

Usage:
tpl.paths.remove(...)
Arguments:
...

character vector of paths

Returned value:

TRUE on success (invisibly)

Examples:
tpl.paths()
tpl.paths.add('/tmp')
tpl.paths()
tpl.paths.remove('/tmp')
tpl.paths()
## might trigger an error:
tpl.paths.remove('/root')

tpl.paths.reset: Reset Template Paths
Description:

Resets to default (NULL) all custom paths where rapport will look for templates.

Usage:
tpl.paths.reset()
Examples:
tpl.paths.reset()

tpl.renew: Renew deprecated template
Description:

Convert old-style template to new-style one (what we really do is just replacing old header syntax with YAML one).

Usage:
tpl.renew(fp, file = NULL)
Arguments:
fp

pointer to an old template (see tpl.find for details)

file

a path to output file. If NULL , result will be flushed to stdout.

tpl.rerun: Reproduce Template
Description:

Runs template with data and arguments included in rapport object. In order to get reproducible example, you have to make sure that reproducible argument is set to TRUE in rapport function.

Usage:
tpl.rerun(tpl)
Arguments:
tpl

a rapport object

Examples:
tmp <- rapport("Example", mtcars, v = "hp", reproducible = TRUE)
tpl.rerun(tmp)

tpl.tangle: Extract template chunk contents
Description:

rapport 's alternative to Stangle - extracts contents of template chunks. If file argument

Usage:
tpl.tangle(fp, file = "", show.inline.chunks = FALSE)
Arguments:
fp

template file pointer (see tpl.find for details)

file

see file argument in cat function documentation

show.inline.chunks

extract contents of inline chunks as well? (defaults to FALSE )

Returned value:

(invisibly) a list with either inline or block chunk contents


© 2011-2013 rapport Development Team | License (AGPL3) | Styled with skeleton.