Title: | A Collection of Modified R Functions to Make Basic Coding More Convenient |
---|---|
Description: | A collection of recycled and modified R functions to aid in file manipulation, data exploration, wrangling, optimization, and object manipulation. Other functions aid in convenient data visualization, loop progression, software packaging, and installation. |
Authors: | Paul Little [aut, cre] |
Maintainer: | Paul Little <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.0.0 |
Built: | 2025-01-29 21:07:21 UTC |
Source: | CRAN |
Transform numeric vector into discrete bins
bin_cont_var(VAR, NUM_GROUPS, ROUND = 3, binNUM = FALSE)
bin_cont_var(VAR, NUM_GROUPS, ROUND = 3, binNUM = FALSE)
VAR |
A numeric vector of values to bin |
NUM_GROUPS |
A positive integer for the number of bins |
ROUND |
A nonnegative integer for displaying bin labels through binned intervals |
binNUM |
Boolean set to TRUE to map bins to numbers. Otherwise, bins are characterized by intervals |
A character or integer vector of collapsed/binned values
calc_JK
calc_JK(EST, LOO_EST, alpha = 0.05)
calc_JK(EST, LOO_EST, alpha = 0.05)
EST |
A numeric vector of parameter estimates |
LOO_EST |
A numeric matrix of parameter estimates where columns correspond to each parameter and rows correspond to each leave one out estimate |
alpha |
A numeric value for constructing (1 - alpha) * 100% confidence intervals |
A list of numeric jackknife summary mean and confidence intervals
chk_threads
chk_threads(NN, ncores)
chk_threads(NN, ncores)
NN |
A positive integer for total iterations to loop over |
ncores |
A positive integer for number of threads |
An integer for number of threads.
Check package is installed
chkInst_PACK(PACK)
chkInst_PACK(PACK)
PACK |
A character string for a package name |
Boolean for TRUE
if package installed
and FALSE
if package is not installed or located
Collapse a subset of values within a vector into a new value
collapse_var(ORIG_VAR, ORIG_VALUES, NEW_VALUE)
collapse_var(ORIG_VAR, ORIG_VALUES, NEW_VALUE)
ORIG_VAR |
The input vector |
ORIG_VALUES |
A subset of values from the input vector to be collapsed |
NEW_VALUE |
The new value to replace
|
A character or numeric vector
Calculates the log(sum(exp(x))) in Rcpp
logSumExp(x)
logSumExp(x)
x |
A numeric vector |
A numeric vector
Construct a dummy-coded matrix for a single variable
make_dummy(x)
make_dummy(x)
x |
A numeric or character vector to convert to a dummy matrix |
A binary indicator matrix of ones and zeros
Substitute a column name of a matrix or data.frame with a new name
name_change(DATA, ORIG_NAME, NEW_NAME)
name_change(DATA, ORIG_NAME, NEW_NAME)
DATA |
A matrix or data.frame |
ORIG_NAME |
A single character column name to alter |
NEW_NAME |
A single character to replace |
An updated data.frame with renamed fields
print_latex_table
print_latex_table( DATA, repeat_VARS = NULL, my_align = NULL, add_table = FALSE, fontsize = NULL, caption = NULL, label = NULL, midrule1 = NULL, latex_comment = NULL, ... )
print_latex_table( DATA, repeat_VARS = NULL, my_align = NULL, add_table = FALSE, fontsize = NULL, caption = NULL, label = NULL, midrule1 = NULL, latex_comment = NULL, ... )
DATA |
A matrix or data.frame to present as a latex table |
repeat_VARS |
A string vector of colnames to avoid repeating values within a column |
my_align |
A string containing letters "l", "r", or "c" for left, right, and center alignment |
add_table |
Boolean set to TRUE to enclose tabular environment with table environment |
fontsize |
Defaults to NULL to not specify a fontsize. Otherwise, possible values are "tiny", "footnotesize", "small", "normalsize", "large", "Large", "LARGE", "huge","Huge" |
caption |
A string to include a table caption |
label |
A string to represent a latex table label |
midrule1 |
Default is set to NULL |
latex_comment |
Add a latex comment above the table for notes |
... |
arguments passed to cat |
No return value
smart_boxplot
smart_boxplot(MAT, mar_down = 8, srt = 45, ...)
smart_boxplot(MAT, mar_down = 8, srt = 45, ...)
MAT |
A numeric matrix of columns to plot as boxplots |
mar_down |
A positive numeric value to allow space below the x-axis for labels |
srt |
A numeric value to control the angle of x-axis labels |
... |
arguments passed to boxplot |
No return value.
smart_colors
smart_colors(nn, alpha = 1, overwrite = FALSE)
smart_colors(nn, alpha = 1, overwrite = FALSE)
nn |
A positive integer greater than or equal to 2 |
alpha |
A positive numeric value less than or equal to one |
overwrite |
Boolean If nn = 2, setting to FALSE will force colors to be white or black |
No return value.
smart_compMATs
smart_compMATs( MAT1, MAT2 = NULL, which_range = NULL, xlab, ylab, show_corr = TRUE, show_plot = FALSE, main = NULL, vec_col = NULL, ... )
smart_compMATs( MAT1, MAT2 = NULL, which_range = NULL, xlab, ylab, show_corr = TRUE, show_plot = FALSE, main = NULL, vec_col = NULL, ... )
MAT1 |
A numeric matrix |
MAT2 |
A second numeric matrix of columns
comparable to MAT1. Default is set to |
which_range |
Default is set to |
xlab |
A string for x-axis label |
ylab |
A string for y-axis label |
show_corr |
Boolean set to TRUE to print Pearson and Spearman correlations |
show_plot |
Boolean set to TRUE to plot comparison of two matrices |
main |
A string for the plot title |
vec_col |
A vector of colors to color scatter plot points |
... |
arguments passed to plot |
No return value.
Construct data.frame with data.frame()
but sets stringsAsFactors
to FALSE
.
smart_df(...)
smart_df(...)
... |
arguments passed to data.frame |
A data.frame
Round numeric values to specific
smart_digits(x, digits = 2)
smart_digits(x, digits = 2)
x |
A numeric vector formatted to have consistently rounded values |
digits |
A positive integer to regulate the number of digits to round to |
Character version of rounded numeric value
Prints a series of dots every few seconds
smart_dots(wait = 300, num_dots = 30)
smart_dots(wait = 300, num_dots = 30)
wait |
A number of seconds to wait before printing "." |
num_dots |
The number of dots to print before printing a message |
No return value.
smart_heatmap
smart_heatmap( MAT = NULL, DIST = FALSE, main = "", width = NULL, height = NULL, GRID = NULL, clustRC = c(TRUE, TRUE), nodePar_col = NULL, nodePar_row = NULL, mar = 2, cex.main = 2, rowData = NULL, colData = NULL, make_key = TRUE, vec_cols = NULL )
smart_heatmap( MAT = NULL, DIST = FALSE, main = "", width = NULL, height = NULL, GRID = NULL, clustRC = c(TRUE, TRUE), nodePar_col = NULL, nodePar_row = NULL, mar = 2, cex.main = 2, rowData = NULL, colData = NULL, make_key = TRUE, vec_cols = NULL )
MAT |
A numeric matrix of values |
DIST |
Boolean set to TRUE to treat MAT as distance matrix. Otherwise, function can perform row/column clustering |
main |
A string for the overall heatmap title |
width |
NULL |
height |
NULL |
GRID |
NULL |
clustRC |
NULL |
nodePar_col |
NULL |
nodePar_row |
NULL |
mar |
NULL |
cex.main |
NULL |
rowData |
NULL |
colData |
NULL |
make_key |
NULL |
vec_cols |
NULL |
No return value.
smart_hist
smart_hist(x, freq = FALSE, dens = TRUE, main = "", ...)
smart_hist(x, freq = FALSE, dens = TRUE, main = "", ...)
x |
A numeric vector |
freq |
Boolean set to |
dens |
Boolean set to |
main |
String for plot title |
... |
arguments passed to hist |
No return value.
Merges two data.frames assuming they have at least one shared column name
smart_merge(x, y, mess = FALSE, ...)
smart_merge(x, y, mess = FALSE, ...)
x |
A data.frame |
y |
A data.frame |
mess |
Default to |
... |
arguments passed to merge |
A merged data.frame
aa = smart_df(a = c(1,2,3),b = c("a","b","c"),c = c(4,5,6)) bb = smart_df(a = c(2,4,5),b = c("b","d","e"),d = c("alpha","beta","gamma")) smart_merge(aa,bb,all.x = TRUE) smart_merge(aa,bb,all.y = TRUE) smart_merge(aa,bb,all = TRUE)
aa = smart_df(a = c(1,2,3),b = c("a","b","c"),c = c(4,5,6)) bb = smart_df(a = c(2,4,5),b = c("b","d","e"),d = c("alpha","beta","gamma")) smart_merge(aa,bb,all.x = TRUE) smart_merge(aa,bb,all.y = TRUE) smart_merge(aa,bb,all = TRUE)
Create directory if it does not exist
smart_mkdir(input_dir)
smart_mkdir(input_dir)
input_dir |
A full path name for a directory to create |
No return value
Sets row/column names to matrix or data.frame
smart_names(MAT, ROW = NULL, COL = NULL)
smart_names(MAT, ROW = NULL, COL = NULL)
MAT |
A matrix |
ROW |
A vector of length equal to |
COL |
A vector of length equal to |
Outputs a matrix or data.frame depending on input object class
Return all associated package versions
smart_pack_versions(pack, repo = "CRAN")
smart_pack_versions(pack, repo = "CRAN")
pack |
A string for the package name |
repo |
A string that takes values "CRAN", "aCRAN", and "cCRAN" for combining options "aCRAN" and "cCRAN". "cCRAN" refers to contributed packages. "aCRAN" refers to archived packages. |
A data.frame of available R packages
Print progress of a for loop
smart_progress(ii, nn, string = ".", iter = 5, iter2 = 200, ...)
smart_progress(ii, nn, string = ".", iter = 5, iter2 = 200, ...)
ii |
A positive integer to track a loop's progress |
nn |
A positive integer for the total number of loop iterations |
string |
A string to print |
iter |
A positive integer for how many multiple iterations to print "." |
iter2 |
A positive integer to end a line of printed "." and track the loop's progress |
... |
arguments passed to cat |
No return value.
Checks if required column names are contained in the matrix or data.frame.
smart_reqNames(DATA, REQ)
smart_reqNames(DATA, REQ)
DATA |
A matrix or data.frame |
REQ |
A string vector of colnames required to be contained in DATA |
No return value.
Drops columns from a matrix or data.frame.
smart_rmcols(OBJ, rm_names)
smart_rmcols(OBJ, rm_names)
OBJ |
A matrix or data.frame |
rm_names |
A string vector of colnames to remove |
A matrix or data.frame
Calls read.table()
but sets
argument stringsAsFactors = FALSE
to prevent
treating character columns as factors.
smart_RT(...)
smart_RT(...)
... |
arguments passed to read.table |
Return is identical to read.table()
Convert numeric values into scientific notation
smart_SN(x, digits = 2)
smart_SN(x, digits = 2)
x |
A numeric vector to convert to scientific notation |
digits |
A positive integer for number of digits to include in notation |
A character vector
smart_solve
smart_solve(mm)
smart_solve(mm)
mm |
A square numeric matrix |
A square numeric matrix.
Should elements passed into table()
contain NA
or NaN
, we want to see them
by default.
smart_table(...)
smart_table(...)
... |
arguments passed to table |
Return a table
aa = c(1,1,2,2,2,3,NA) table(aa) smart_table(aa)
aa = c(1,1,2,2,2,3,NA) table(aa) smart_table(aa)
Calls write.table()
setting
parameters row.names
and quote
to FALSE
.
smart_WT(...)
smart_WT(...)
... |
arguments passed to write.table |
Return is identical to write.table()