R utility functions library.
devtools::install_github("five-dots/rutils")
library(rutils)
remove_outliers(data, x, outlier_percent = NULL)
Remove outliers from data.frame column by upper/lower percent.
as_numeric_factor(x)
Convert factor to numeric. Just implement the discussion here.
read_last_file(dir, file_regex = NULL)
Wrapper function ofdata.frame::fread()
andreadRDS()
to read the latest csv file in the directory. Automatically select a read function based on the file’s extension. Currenty supports.csv
,.rds
and.zip
.get_date_from_file(path)
ExtractDate
object from file path that ends with “YYYY-mm-dd”.
gg_theme()
Simpleggplot2
theme.
lm_pvalue(fit)
Extract model’s p-value fromlm
object.
unescape_html(strings)
Vectorized function to convert HTML string (e.g. convert “S&P500” to “S&P500”) as discussed here.log_str(message)
Convenient function for logging messages when you run a Rscript. It writes a message with the date time and the executed file path.
make_duration(hhmmss)
Make alubridate::duration()
object from “HH:MM:SS” string.make_dt_from_msec(msec, tz = "America/New_York")
Make a POSIXct object by elapsed milliseconds from UNIX epoch.make_today_time(hour = 0, min = 0, sec = 0, tz = "America/New_York")
Make a POSIXct of today’s with time specified.
view_types()
Wrapper function to view object type information bytypeof()
,mode()
,class()
,pryr::otype()
,pryr::ftype()
,pryr::sexp_type()
.view_data()
Combinestr()
,head()
andtail()
to view data.
- [ ] Expand test coverage.