Learn R Programming

tfse

Various useful functions for working with data and writing functions

Install

Install from CRAN

## from CRAN repo
install.packages("tfse")

Install dev version from Github

## from github
remotes::install_github("mkearney/tfse")

Usage

Scales

Rescale to standard (0-1) scale

## 0-1 scale
rescale_standard(-2:2)
#> [1] 0.00 0.25 0.50 0.75 1.00

Rescale to normal (mean = 0; sd = 1) scale

## z scores
rescale_normal(-2:2)
#> [1] -1.2649111 -0.6324555  0.0000000  0.6324555  1.2649111

Rescale to arbitrary lower/upper bounds

## specify new scale bounds
rescale_pointscale(-2:2, 1, 10)
#> [1]  1.00  3.25  5.50  7.75 10.00

Citations

Print out the APA-formatted citation for R packages.

## print out APA citation for {rtweet}
apa_citation("rtweet")
#> ↪ Adding APA citation of {rtweet} to clipboard!
#> âś” Ready to paste!
#> 
#> Kearney, M. W. (2018). rtweet: Collecting twitter data (R package version
#>     0.6.7) [Computer software]. The Comprehensive R Archive Network. Available
#>     from https://cran.r-project.org/package=rtweet

Annotate script files

Use box_code() to add a header-like chunk to your clipboard–paste in script as desired.

## store text in clipboard
box_code("EXAMPLE #1")

## the pasted output:
##----------------------------------------------------------------------------##
##                                 EXAMPLE #1                                 ##
##----------------------------------------------------------------------------##

Regular expressions

Get all regular expression matches (using easier looka-heads/look-behinds)

## some text
x <- c("This *is* a test", 
  "#this *was* a test", 
  "This *will* be a test!",
  "This *has been* a test; it *is* great.")

## return text between asterisks, return as atomic vector
regmatches_(x, "(?<=\\*)\\S[^*]+(?=\\*)", drop = TRUE)
#> [1] "is"       "was"      "will"     "has been" "is"

Github

Figure out the name of a Github repo for a given package

## repo name of devtools
desc_gh_repo("devtools")
#> [1] "r-lib/devtools"

Convert a Github link to the raw URL version

## path to raw version of Github file
github_raw("https://github.com/mkearney/driven-snow/blob/master/theme/driven-snow.rstheme")
#> [1] "https://raw.githubusercontent.com/mkearney/driven-snow/master/theme/driven-snow.rstheme"

Help

View the help documentation

## view R help documentatoin
help(package = "tfse")

about tfse

  • This is my personal R package of utility functions
  • Why tfse? The acronym was creatively reconfigured from its originally intended state

Copy Link

Version

Install

install.packages('tfse')

Monthly Downloads

16

Version

0.5.0

License

MIT + file LICENSE

Maintainer

Michael W. Kearney

Last Published

February 11th, 2019

Functions in tfse (0.5.0)

data_set

Create data set
desc_get_var

Description variables
github_raw

Generate link to raw Github file
copy_function

Copy function to clipboard
count_na

Count missing values
menuline

menuline
.Renviron

.Renviron file
file_edit

Open file in text editor
gregexpr_

smart gregexpr wrapper
%P%

Paste grapes
pbcopy

pbcopy
match_arg

match arg to choices
max_na

Filter based on proportion of missing data
min_var

Select columns with minimum amount of variance
home

Home directory
add_arg_if

Add defaults to argument list
apa_citation

APA citation of R package
%>%

Pipe operator
save_RDS

Save RDS
rm_.DS_Store

Remove pesky .DS_Store files
this_in_that

Where is this in that?
peel_lists

peel lists
pmsg

Paste collapse input and print as message
print_start

Print message about starting a task
rename_git_repo

Rename git repo code
rescale

Standard: Rescale values to a standard normal scale
psub

Paste sub
readlines

readlines
read_RDS

Read RDS
readline_

readline_
regmatches_

extract reg expr matches
substrev

Sub string reverse
set_names

Set names
set_renv

Set R environment variable
trim_ws

trim_ws
un_zip

Unzip files into directory
nin

Return lhs values not in rhs values
tfse

tfse: Various Useful Functions
boxcode

boxcode
cc

Combine comma separated strings
unset_row_names

Unset row names
n_uq

Number of unique elements
paste_collapse

Paste collapse
search_these_files

Search these files
na_omit

Omit missing values/rows
print_as_col

Print data frame as a single column
set_class

set class
print_complete

Print message about completing a task
search_files

search_files
search_function

search functions
shhh

execute expression quietly
show_connections

show connections
write_function

Write function to file