Title: | Simple R Tools for Analysis and Visualizations |
---|---|
Description: | Provides functions (R, C++) to speed up array calculations. Includes various tools for prettier visualizations via R base plots. |
Authors: | Zhengjia Wang [aut, cre, cph], John Magnotti [aut, cph] |
Maintainer: | Zhengjia Wang <[email protected]> |
License: | GPL-3 |
Version: | 0.1.7 |
Built: | 2024-10-29 03:30:48 UTC |
Source: | https://github.com/dipterix/rutabaga |
Pipe Function To Paste Two Characters
x %&% y
x %&% y
x |
character |
y |
character |
paste0(x,y)
Same As Points, But Can Be Jittered
(maturing)
add_points(x, y, jitr_x = 0, pch = 19, ...)
add_points(x, y, jitr_x = 0, pch = 19, ...)
x , y
|
plot data |
jitr_x |
jitter shift size for x |
pch |
data point type, default is 19, See |
... |
other params to |
pdf wrapper that evaluates an arbitrary expression.
as_pdf(fname, w, h, expr, TEST = FALSE, bg = "white")
as_pdf(fname, w, h, expr, TEST = FALSE, bg = "white")
fname |
file path |
w |
the requested width of the PDF |
h |
the requested height of the PDF |
expr |
the expression to evaluate to produce the plot |
TEST |
if FALSE (the default) print to PDF, otherwise print to the current graphics device |
bg |
set the background color of the PDF, defaults to 'white' |
the output of the resulting expression (the plot is likely produced by side effect but may additionally 'return' a value)
Make nice plot titles
as_title(x, ...) ## S3 method for class 'formula' as_title(x, ...) ## Default S3 method: as_title( x, capitalize_all = TRUE, excluded = c("is", "are", "vs", "v.s.", "from", "of", "be", "for", "over"), ... ) ## S3 method for class 'fres' as_title(x, ...) ## S3 method for class 'tres' as_title(x, ...)
as_title(x, ...) ## S3 method for class 'formula' as_title(x, ...) ## Default S3 method: as_title( x, capitalize_all = TRUE, excluded = c("is", "are", "vs", "v.s.", "from", "of", "be", "for", "over"), ... ) ## S3 method for class 'fres' as_title(x, ...) ## S3 method for class 'tres' as_title(x, ...)
x |
title content |
... |
pass to other methods |
capitalize_all |
make the first letter cap |
excluded |
exclude making first letter cap, numeric vector |
## Not run: # Display normal title plot_clean(1,1, main = as_title('this is title')) # Only capitalize the first character plot_clean(1,1, main = as_title('this is title', capitalize_all = F)) # What if title is a formula plot_clean(1,1, main = as_title(p[value](beta[1]) < ~.(0.01) ~ ' is significant')) # Display t-statistics plot_clean(1,1) t_stat = get_t(rnorm(10)) title(main=as_title(t_stat)) ## End(Not run)
## Not run: # Display normal title plot_clean(1,1, main = as_title('this is title')) # Only capitalize the first character plot_clean(1,1, main = as_title('this is title', capitalize_all = F)) # What if title is a formula plot_clean(1,1, main = as_title(p[value](beta[1]) < ~.(0.01) ~ ' is significant')) # Display t-statistics plot_clean(1,1) t_stat = get_t(rnorm(10)) title(main=as_title(t_stat)) ## End(Not run)
Make cbind magrittr compatible (stable)
cbind_list(ll)
cbind_list(ll)
ll |
the list to bind, each element will be a column |
Ensure Data Are Within Some Bounds
(stable)
clip_x(x, lim)
clip_x(x, lim)
x |
data |
lim |
clip range, length of 1 or more. If length(lim) is 1, then the clip is symmetric |
add decoration (frames) to plots based on their layout location
create_frames( layout, common = NULL, bottom = NULL, left = NULL, top = NULL, right = NULL, env = parent.frame(), exclude = NULL )
create_frames( layout, common = NULL, bottom = NULL, left = NULL, top = NULL, right = NULL, env = parent.frame(), exclude = NULL )
Create directory signature
dir_signature( path = ".", file.info = FALSE, md5sum = TRUE, recursive = TRUE, ... )
dir_signature( path = ".", file.info = FALSE, md5sum = TRUE, recursive = TRUE, ... )
path |
directory path to generate signatures |
file.info , md5sum , recursive , ...
|
passed to |
Clauses With Side Effects (Plotting Etc)
(questioning)
do_if(boolean_expression, if_clause, else_clause = NULL)
do_if(boolean_expression, if_clause, else_clause = NULL)
boolean_expression |
expression that returns true or false |
if_clause |
if true, do if_clause |
else_clause |
if false, do else_clause |
Polygon plot
do_poly(x, y, col, alpha = 50, border = NA, ...)
do_poly(x, y, col, alpha = 50, border = NA, ...)
x , y
|
x and y |
col |
color |
alpha |
0-255 transparency |
border |
border of polygon |
... |
passed to polygon |
Draw Symmetric Error Bars
(stable)
ebar_polygon( x, y, sem, alpha = 100, col = "black", fill = col, stroke = col, border = NA, add_line = TRUE, lwd = 1, ... )
ebar_polygon( x, y, sem, alpha = 100, col = "black", fill = col, stroke = col, border = NA, add_line = TRUE, lwd = 1, ... )
x , y
|
plot data |
sem |
error bar half width |
alpha |
transparency |
col |
color |
fill |
error bar color |
stroke |
if add lines, line color |
border |
errorbar border width |
add_line |
add line(x,y) or not |
lwd |
line weight |
... |
passed to |
## Not run: plot_clean(0:10, -1:5, xlab = 'X') ruta_axis(side = 2, at = -1:8) ebar_polygon(1:10, (1:10)/2, rnorm(10)) ## End(Not run)
## Not run: plot_clean(0:10, -1:5, xlab = 'X') ruta_axis(side = 2, at = -1:8) ebar_polygon(1:10, (1:10)/2, rnorm(10)) ## End(Not run)
Draw Symmetric Error Bars
ebars( x, y = NULL, sem = NULL, length = 0.05, type = "n", col = "black", pt.col = col, code = 2, ... )
ebars( x, y = NULL, sem = NULL, length = 0.05, type = "n", col = "black", pt.col = col, code = 2, ... )
x , y
|
data to plot |
sem |
error range (half) |
length |
line length |
type |
type of xy data see points |
col |
default color for points and error areas |
pt.col |
point colors |
code |
arrow code |
... |
other params passed to ebars.y |
## Not run: plot_clean(0:10, -1:5, xlab = 'X') ruta_axis(side = 2, at = -1:8) ebars(x = c(2, 4), y = c(0, 3), sem = c(1, 0.5), col = c(2, 3)) ## End(Not run)
## Not run: plot_clean(0:10, -1:5, xlab = 'X') ruta_axis(side = 2, at = -1:8) ebars(x = c(2, 4), y = c(0, 3), sem = c(1, 0.5), col = c(2, 3)) ## End(Not run)
Execute the function (usually for its side effect) then return (invisibly) the input to the function
F_NOOP(x, FUN, ...)
F_NOOP(x, FUN, ...)
x |
input |
FUN |
function to apply on |
... |
additional parameters passing to |
Ensure that the file names ends in ".pdf"
fix_pdf_name(fname)
fix_pdf_name(fname)
fname |
potential file name |
(questioning)
format_stat(nm, stats = c("b", "t", "p"))
format_stat(nm, stats = c("b", "t", "p"))
nm |
statistics |
stats |
names of statistics |
Get Data Range From A Collection Of Named Lists
(questioning)
get_data_range(ll, name = "range", ...)
get_data_range(ll, name = "range", ...)
ll |
list |
name |
element name |
... |
additional params for get_list_elements |
(questioning)
get_f(formula, ...) format_f(lm.mod, test_name = "All")
get_f(formula, ...) format_f(lm.mod, test_name = "All")
formula , ...
|
passed to lm |
lm.mod |
linear model returned by lm() |
test_name |
name |
Get the file name from a full file path
get_filename(full_path, keep_extension = FALSE)
get_filename(full_path, keep_extension = FALSE)
full_path |
path to file |
keep_extension |
whether the file extension should be retained (defaults to FALSE) |
Get Elements/Slot/Attributes From List
(stable)
get_list_elements( ll, name, drop_nulls = TRUE, is_attr = FALSE, use_sapply = TRUE, ... )
get_list_elements( ll, name, drop_nulls = TRUE, is_attr = FALSE, use_sapply = TRUE, ... )
ll |
list of elements |
name |
attribute/name/slot to extract |
drop_nulls |
drop NULL results |
is_attr |
are we extracting attributes? |
use_sapply |
try to return a matrix/vector if possible? |
... |
if is_attr, additional params to |
(questioning)
get_t(...)
get_t(...)
... |
passed to t.test |
Get Hex Color With Transparency
getAlphaRGB(colname, alpha)
getAlphaRGB(colname, alpha)
colname |
name or number of color |
alpha |
transparency |
## Not run: getAlphaRGB('red', 0.5) ## End(Not run)
## Not run: getAlphaRGB('red', 0.5) ## End(Not run)
Check if a is within the range of b
(stable)
is_within(a, b) a %within% b
is_within(a, b) a %within% b
a |
element to check (numeric) |
b |
vector of numbers |
Return Jittered X
(experimental)
jitr(x, len = length(x), r)
jitr(x, len = length(x), r)
x |
data |
len |
length of x |
r |
jitter size |
Function To Return Mean And Standard Deviation (Na Ignored by default)
(stable)
m_sd(x, na.rm = TRUE)
m_sd(x, na.rm = TRUE)
x |
data |
na.rm |
remove NAs? |
Function To Return Mean And Standard Error
(stable)
m_se(x) mat_m_se(m, DIM = 2)
m_se(x) mat_m_se(m, DIM = 2)
x |
data |
m |
matrix data |
DIM |
margin, 1 for row, 2 for column. See apply |
Evaluate an expression, but then return the input
NOOP(x, expr = NULL)
NOOP(x, expr = NULL)
x |
object to return |
expr |
expression to run |
Return True If Not Na
(stable)
make it easier to say not is.na in a pipe'd context
not_NA(x) not_NA(x)
not_NA(x) not_NA(x)
x |
data |
Return True If Not Null
(stable)
not_null(x)
not_null(x)
x |
data |
Create A Blank Plot With Given X And Y Range
(stable)
plot_clean( xlim, ylim, x = 1, y = 1, type = "n", xlab = "", ylab = "", cex.main = rave_cex.main, cex.axis = rave_cex.axis, cex.lab = rave_cex.lab, ... )
plot_clean( xlim, ylim, x = 1, y = 1, type = "n", xlab = "", ylab = "", cex.main = rave_cex.main, cex.axis = rave_cex.axis, cex.lab = rave_cex.lab, ... )
xlim |
numeric vector |
ylim |
numeric vector |
x |
x |
y |
y |
type |
default is 'n', i.e. plot nothing. See |
xlab |
x label |
ylab |
y label |
cex.main |
title font size |
cex.axis |
axis ticks font size |
cex.lab |
axis label font size |
... |
other params passed to |
## Not run: # create a blank plot with x from 0 to 10 and y from 1 to 5 plot_clean(0:10, 1:5, xlab = 'X') ## End(Not run)
## Not run: # create a blank plot with x from 0 to 10 and y from 1 to 5 plot_clean(0:10, 1:5, xlab = 'X') ## End(Not run)
Show A Blank Plot With Messages
(maturing)
plot_msg(main = "No Conditions Specified")
plot_msg(main = "No Conditions Specified")
main |
the title/msg to show |
## Not run: plot_msg("Let's Say Something") ## End(Not run)
## Not run: plot_msg("Let's Say Something") ## End(Not run)
Easy Way To Get +/- From A Long Vector
plus_minus(x, d)
plus_minus(x, d)
x |
data |
d |
plus minus value(s) |
Easy Way To Get +/- From A Long Vector
(deprecated)
pm(x, d)
pm(x, d)
x |
data |
d |
plus minus value(s) |
output of a function, but return its input to allow chaining
print_summary(x, FUN = summary, ...)
print_summary(x, FUN = summary, ...)
x |
object to print summary |
FUN |
function to print on |
... |
additional parameters passing to |
Enforce Sum To 1, Ignoring Na In The Sum, But Keeping Them In The Output
(questioning)
pscl(x)
pscl(x)
x |
data |
Barplot Function That Uses All The Rave Sizes And Colors
(stable)
rave_barplot( height, cex.axis = rave_cex.axis, cex.lab = rave_cex.lab, cex.names = rave_cex.lab, ... )
rave_barplot( height, cex.axis = rave_cex.axis, cex.lab = rave_cex.lab, cex.names = rave_cex.lab, ... )
height , cex.axis , cex.lab , cex.names , ...
|
passed to barplot but the default values are changed |
Make rbind magrittr compatible (stable)
rbind_list(ll)
rbind_list(ll)
ll |
the list to bind, each element will be a row |
Remove the last k elements from a vector (list) Returns x (with a warning) if k < 1
remove_tail(x, k = 1)
remove_tail(x, k = 1)
x |
the vector |
k |
the number of items to remove |
Get A Integer Interval That Contains X
(maturing)
round_range(x)
round_range(x)
x |
vector/matrix, numeric |
## Not run: # 0 - 11 round_range(0.5:10.5) ## End(Not run)
## Not run: # 0 - 11 round_range(0.5:10.5) ## End(Not run)
row applier with an additional index variable, ii
row_apply_ii(mat, FUN_, ...)
row_apply_ii(mat, FUN_, ...)
mat |
matrix or array |
FUN_ |
function to apply to each row |
... |
additional parameters passing to |
helper to do row scaling
row_scale(mat)
row_scale(mat)
mat |
a matrix |
A Neat Way To Show Axis
(stable)
ruta_axis( side, at, tcl = -0.3, labels = at, las = 1, cex.axis = rave_cex.axis, cex.lab = rave_cex.lab, mgpy = c(3, 0.6, 0), mgpx = c(3, 0.75, 0), ... )
ruta_axis( side, at, tcl = -0.3, labels = at, las = 1, cex.axis = rave_cex.axis, cex.lab = rave_cex.lab, mgpy = c(3, 0.6, 0), mgpx = c(3, 0.75, 0), ... )
side |
1 to 4: bottom, left, up, right. See |
at , tcl , labels , las , mgpy , mgpx , ...
|
passed to |
cex.axis |
tick size |
cex.lab |
label size |
## Not run: # create a blank plot with x from 0 to 10 and y from 1 to 5 plot_clean(0:10, 1:5, xlab = 'X') ruta_axis(side = 1, at = 1:8) ## End(Not run)
## Not run: # create a blank plot with x from 0 to 10 and y from 1 to 5 plot_clean(0:10, 1:5, xlab = 'X') ruta_axis(side = 1, at = 1:8) ## End(Not run)
sapply with an additional index variable, ii
sapply_ii(X, FUN_, simplify = TRUE, USE.NAMES = TRUE, ...)
sapply_ii(X, FUN_, simplify = TRUE, USE.NAMES = TRUE, ...)
X |
vector or list |
FUN_ |
function to apply on |
simplify , USE.NAMES , ...
|
passed to |
0-1 Scale The Data So We Can Manage The Plot Ranges Easily
(stable)
scale_01(x)
scale_01(x)
x |
data to be rescaled |
Convert vector into comma-separated string
str_collapse(x, by = ", ", ...)
str_collapse(x, by = ", ", ...)
x |
the vector to collapse |
by |
the separating token (default is ', ') |
... |
further arguments for paste0 |
a character vector as produced by paste0
Useful For Plotting When You Want To Go A Bit Beyond The Data
(experimental)
stretch(x, pct)
stretch(x, pct)
x |
data |
pct |
stretch percentage |
Function for repeatedly writing plots to PDFs
to_pdf(PLOT, w, h, mar = rep(1, 4))
to_pdf(PLOT, w, h, mar = rep(1, 4))
PLOT |
a function that produces a plot |
w |
the requested width of the PDF |
h |
the requested height of the PDF |
mar |
the margins of the PDF, set by a call to par(mar=mar). Defaults to c(1,1,1,1) |
A function that takens optional arguments to the PLOT function and fname, the name of the PDF. One-off changes to w, h, and mar, are specified with width, height, and margin, respectively
Trim Data By Standard Error
(stable)
trim(x, cutoff = 6)
trim(x, cutoff = 6)
x |
data to be trimmed |
cutoff |
default is 6, then x is clipped +-6 times sd |
Mean Of Data After Trimmed
(questioning)
trimmed.mean(x, cutoff = 4)
trimmed.mean(x, cutoff = 4)
x , cutoff
|
passed to trim |
Sd Of Data After Trimmed
(questioning)
trimmed.mse(x, cutoff = 4)
trimmed.mse(x, cutoff = 4)
x , cutoff
|
passed to trim |
like which.min, but for equality useful when an expression for x or y is long
which.equal(x, y)
which.equal(x, y)
x , y
|
vectors to compare |