Appendix B Online: Functions

A searchable table of functions covered in the book (and chapters where they appeared) is available in the functions.html file or at https://smach.github.io/R4JournalismBook/functions.html.

Function, Package, Chapter

%>%, magrittr and dplyr, 5

%<>%, magrittr, 12

%in%, base R, 7

?, base R, 2

??, base R, 2

<-, base R, 2

addMarkers(), leaflet, 11

addSearchGoogle(), leaflet.extras, 11

addSearchOSM(), leaflet.extras, 11

addTiles(), leaflet, 11

adorn_totals(mydf), janitor, 14

anti_join(df1, df2, by = c(“df1col” = “df2col”)), dplyr, 8

any(myvec == “mycondition”), base R, 13

append_data(shape_object, data_object, key.shp = colname, key.data = colname), tmaptools, 11

apply(mydata, margin, myfunction), base R, 15

arrange(mydf, col), dplyr, 5

as.character(mycol), base R, 5

as.Date(“yyyy-mm-dd”), base R, 13

as.numeric(mycol), base R, 5

barplot(myvec), base R, 6

basename(“http://myurl.com/filename.html”), base R, 16

bind_rows(), dplyr, 7

boxplot(myvec), base R, 6

c(), base R, 2

case_when(), dplyr, 10

cbind(df1, df2), base R, 3

census_api_key(“Your Census Key”), tidycensus, 11

clean_names(mydf), janitor, 4

colnames(mydf), base R, 4

colorBin(), leaflet, 11

colorFactor(), leaflet, 11

colorNumeric(), leaflet, 11

colorQuartile(), leaflet, 11

convert(“oldfile.ext1”, “newfile.ext2”), rio, 4

convert_pdf(“my.pdf”, format = “xlsx-single”, api_key = “YourAPIKeyHere”), pdftables, 14

cor(vec1, vec2), base R, 12

count(mydf, mygroupcolumn), dplyr, 8

cut(), base R, 10

data(), base R, 4

data.frame(vec1, vec2, stringsAsFactors = FALSE), base R, 4

datatable(mydf), DT, 12

demo(), base R, 6

demo(colors), base R, 6

describe(mydf), Hmisc or psych, 5

difftime(dateobject1, dateobject2), base R, 13

dim(mydf), base R, 5

dimnames(mydf), base R, 5

dir(), base R, 7

dmy(“dd-mm-yyyy”), lubridate, 13

download.file(“fileURL”, “destination_file_name”), base R, 4, 11

dygraph(mytimeseries), dygraphs, 3

edit_r_environ(), usethis, 11

edit_rstudio_snippets(), usethis, 6

elec_pcts_by_row(mydata, c(“candidate1”, “candidate2”), “TotalColumn”), rmiscutils, 12

elect_find_winner(“myFileOrObject”, startcolnum, endcolnum), rmiscutils, 12

expect_equal(myfun(myarg), myExpectedValue), testthat, 10

expect_type(myfun(myarg), “myExpectedType”), testthat, 10

export(myobject, “myfile.ext”), rio, 4

extract_tables(), tabulizer, 14

facet_grid(), ggplot2, 9

facet_wrap(), ggplot2, 9

fct_reorder(vectorToReorder, vectorToReorderBy), forcats, 6

file.copy(“path/to/file/myfile”, “path/to/copy/to”, overwrite = TRUE or FALSE), base R, 7

file.exists(“filename”), base R, 7

filter(mydf, conditional statement), dplyr, 5, 8

floor_date(my_date_object, “unit”), lubridate, 13

function(), base R, 10

gather(mydf, key, value, ColumnsYouWantToGather), tidyr, 14

geom_bar(), ggplot2, 6

geom_boxplot(), ggplot2, 6

geom_col(), ggplot2, 6

geom_line(), ggplot2, 6

geom_point(), ggplot2, 6

geom_point(position = “jitter”), ggplot2, 9

geom_smooth(), ggplot2, 12

get_acs(), tidycensus, 11

getSymbols(), quantmod, 3

getwd(), base R, 7

ggplot(mydf, aes(x = myxcolumn, y = myycolumn)) + my_geom(), ggplot2, 6

ggplotly(my_ggplot2_object), plotly, 9

gio_batch_geocode(myaddressvec), rgeocodio, 11

glimpse(mydf), dplyr, 5, 11

glue(“{myvar1} some text {myvar2} more text”), glue, 11

group_by(colname), dplyr, 8

gsub(), base R, 11

head(myobject), base R, 5

help(), base R, 2

here::here(), here, 7

hist(myvec), base R, 6

HTML(), htmltools, 11

html_attr(‘href’), rvest, 16

html_nodes(my_html, my_css), rvest, 16

html_text(), rvest, 16

htmltab(“myURL”, which = tablenum), htmltab, 4

identical(obj1, obj2), base R, 5

if(), base R, 10

ifelse(condition, valueIfTrue, valueIfFalse), base R, 10

import(“myfile.ext”), rio, 4

inner_join(df1, df2, by = c(“df1col” = “df2col”)), dplyr, 8

install.packages(“packagename”), base R, 2

install_github(“username/packagerepo”), remotes, 4

is.numeric(mycol), base R, 5

labelOptions(), leaflet, 11

lag(myvector), dplyr, 13

lapply(mydata, myfun), base R, 7

last_map(), tmap, 11

lead(myvector), dplyr, 13

left_join(df1, df2, by = c(“df1col” = “df2col”)), dplyr, 8

length(myobject), base R, 2

library(packagename), base R, 2

list.files(), base R, 7

load(“myfilename.Rdata”), base R, 4

map_df(mydata, myfun), purrr, 7

max(vec), base R, 5

mdy(“mm/dd/yyyy”), lubridate, 13

merge(df1, df2), base R, 8

methods(class=class(myobject)), base R, 4

min(vec), base R, 5

min_rank(mydf$col), dplyr, 14

months(), base R, 10

mutate(mydf,newcolname = someFunction), dplyr, 8

mutate_at(), dplyr, 15

mutate_geocode(mydf, myaddresscol), ggmap, 11

mylist[[n]], base R, 7

n(), dplyr, 8

names(myobject), base R, 3

nchar(myobject), base R, 2

ncol(mydf), base R, 4

nrow(mydf), base R, 4, 8

number_with_commas(mydf$mycol), rmiscutils, 4

options(scipen = 999), base R, 9

options(width = n), base R, 11

p_install(packagename1), pacman, 2, 5

p_install_gh(“username/packagerepo”), pacman, 4

parse_number(myvec), readr, 4

paste(myvector, collapse = “,”), base R, 14

paste(string1, string2, sep = “myseparator”), base R, 11

paste0(string1, string2), base R, 9, 10, 11

paths_allowed(“http://www.myurl.com/path/”), robotstxt, 16

percent(myfraction), scales, 15

plot(mydata), base R, 6

qplot(), ggplot2, 6

qtm(mysfobject), tmap, 11

range(vec), base R, 5

rbind(df1, df2), base R, 3

read_html(“http://www.myurl.com/myfile.html”), rvest, 16

read_shape(“myshapefile.shp”) or read_shape(“myshapefile.shp” as.sf = TRUE), tmaptools, 11

read_xlsx(“myspreadsheet.xlsx”, range=“startcell:endcell”), readxl, 14

readRDS(“filename.rds”), base R, 4

remove_empty(mydf, “cols”), janitor, 12

rename(mydf, newcolname1 = oldcolname1, newcolname2 = oldcolname2), dplyr, 6

render(“myRMarkdownFileName.Rmd”, output_format=“html_document”, output_file = “myhtmlfile.html” ), rmarkdown, 15

rep(myitem,numtimes), base R, 4

rm(myobject), base R, 4

round(mynum, numDecimalPlaces), base R, 8

save(object1, object2, file = “myfilename.Rdata”), base R, 4

save_tmap(), tmap, 11

saveRDS(myobject, file = “filename.rds”), base R, 4

saveWidget(myhtmlwidget, “filename.html”), htmlwidgets, 3,11,12

scale_color_gradient(), ggplot2, 9

scale_color_grey(), ggplot2, 9

scale_color_manual() or scale_color_brewer(), ggplot2, 9

scale_fill_grey(), ggplot2, 9

scale_fill_manual() or scale_fill_brewer(), ggplot2, 9

select(mydf, colname1, colname2), dplyr, 5

select(mydf, contains(“mypattern”)), dplyr, 14

select_if(mydf, is.numeric), dplyr, 5

seq(), base R, 10

seq.Date(), base R, 13

seq_along(myvec), base R, 16

set_projection(mysfobject, projection = “myprojection”), tmaptools, 11

setView(mymap, lon, lat, zoom), leaflet, 11

setwd(“path/to/newdirectory”), base R, 7

skim(mydf), skimr, 5

slice(mydf, n), dplyr, 5,11

sort(myvec), base R, 6

source(“myfile.R”), base R, 3

spread(mydf, columnToSpread, columnWithValues), tidyr, 14

st_read(“myshapefile.shp”), sf, 11

sum(myvec), base R, 8

summarize(mydf, newcol = somFunction()), dplyr, 8

summary(mydf), base R, 5

Sys.Date(), base R, 10

Sys.setenv(ITEM = “Value”), base R, 11

t(mydf), base R, 14

table(myvec), base R, 8

tabyl(myvec), janitor, 8

tail(myobject), base R, 5

test_that(), testthat, 10

theme(), ggplot2, 9

tibble(vec1, vec2, vec3), tibble, 4

tm_polygons(), tmap, 11

tm_shape(), tmap, 11

tmap_mode(), tmap, 11

top_n(mydf, numrows, rankcol), dplyr, 6

ttm(), tmap, 11

ungroup(mydf), dplyr, 13

union(vec1, vec2), base R, 11

unique(myvec), base R, 7

unloadNamespace(“packageName”), base R, 13

unname(myobj), base R, 8

unzip(“myfile.zip”), base R, 11

use_course, usethis, 5

View(mydf), base R, 8

walk(mydata, myfunction), purrr, 15

walk2(myfirstvector, mysecondvector, myfunction), purrr, 16

weekdays(my_date_object), base R, 13

which.max(vec), base R, 5

which.min(vec), base R, 5

ymd(“yyyy-mm-dd”), lubridate, 13