/rutils

R’s utility functions library.

Primary LanguageROtherNOASSERTION

https://travis-ci.org/five-dots/rutils.svg?branch=master

rutils

R utility functions library.

Installation

devtools::install_github("five-dots/rutils")
library(rutils)

Functions in this package

data.frame

  • remove_outliers(data, x, outlier_percent = NULL) Remove outliers from data.frame column by upper/lower percent.

factor

  • as_numeric_factor(x) Convert factor to numeric. Just implement the discussion here.

file

  • read_last_file(dir, file_regex = NULL) Wrapper function of data.frame::fread() and readRDS() 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) Extract Date object from file path that ends with “YYYY-mm-dd”.

plot

  • gg_theme() Simple ggplot2 theme.

stats

  • lm_pvalue(fit) Extract model’s p-value from lm object.

string

  • 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.

time

  • make_duration(hhmmss) Make a lubridate::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.

viewer

  • view_types() Wrapper function to view object type information by typeof(), mode(), class(), pryr::otype(), pryr::ftype(), pryr::sexp_type().
  • view_data() Combine str(), head() and tail() to view data.

TODOs

  • [ ] Expand test coverage.