Miscellaneous R functions Karl wanted to reuse. Inspired by kimisc.
For a similar grab-bag of Python and Stata scripts, see https://github.com/karldw/useful_scripts.
remotes ::install_github("karldw/kdw.junk")box_home– Find Boxdropbox_home– Find Dropbox
is_id– Do variables uniquely ID rows? (Works withdplyr::selectsyntax for local and remote tables. For local tables, faster when data.table is installed.).ensure_id_vars– Ensure variables uniquely ID rows (works withdplyr::selectsyntax; useful in pipelines).
binscatter– Provide a command like binscatter in Stata, based on binsreg, but with a formula interface and plotting support for fixed effects.capture_plot_output– Likeutils::capture.output(), when the expression would open a graphics device.configure_tikzDevice– Prepare to use tikzDevicesave_plot– Saveggplotgraphic with aspect ratio more appropriate for slides or letter paper (usescairo_pdffor better graphics).- Offers a
reproducibleoption to reset file timestamps.
- Offers a
auto_render– Render and automatically re-renderrmd,md, ortexfiles.cite_attached_packages– Generate biblatex citations for the attached packages.clear_all– Delete everything in session.get_cores– Get number of cores available, with a reasonable max.get_os– Get current OS.install_lazy– Install packages if necessary.is.connection– Test if object is a connection.make_better_names– Improve a character vector of names.memory_limit– Set a memory limit (Linux and Windows only).month_to_quarter– Convert months to quarters.make_monthly– Convert date to monthly (day of month set to 1).rename_cols– Rename columns with a dict-like approach.st_union_intersection– Union intersectingsfgeometries.stopif– Inverse ofstopifnot.truncate_bytes– Truncate a string to a particular length in bytes (not very efficiently).winsorize– winsorize in a way that handles point masses.
read_dta– Wrapper aroundhaven::read_dtato fix hassles with attributes and factors.
Does what is says on the box.
hol_christmas_dayhol_columbus_dayhol_daylight_savinghol_easterhol_george_washington_birthdayhol_good_fridayhol_inauguration_dayhol_independence_dayhol_labor_dayhol_martin_luther_king_dayhol_memorial_dayhol_new_years_dayhol_presidents_dayhol_thanksgiving_dayhol_us_federal_holidayshol_veterans_day
explain_analyzepg_add_foreign_keypg_add_indexpg_add_primary_keypg_vacuum
read_data– userio::import()instead.lapply_parallel– usefurrr::future_map()instead.lapply_bind_rows– usefurrr::future_dfr()instead.
vec2string– you're better off usingglue::glue()most of the time.make_join_safer– use safejoin instead.- Takes a
dplyr::*_joinfunction and return a new function that performs additional checks to avoid many-to-many merges
- Takes a
merge_stata– use safejoin instead.- Defined a merge function that mirrored Stata's
merge
- Defined a merge function that mirrored Stata's
narrate– userlang::inform()instead.update_packages– update packages and reinstall everything that depends on Rcpp when Rcpp is updated. Deprecated because that doesn't seem to be an issue anymore.
felm_strict– Runlfe::felm()strictly.- Use
fixest::feols()instead
- Use