Skip to content

Commit

Permalink
Merge pull request #55 from Metropolitan-Council/look
Browse files Browse the repository at this point in the history
data.table look function
  • Loading branch information
eroten authored Mar 10, 2023
2 parents a195749 + 824fd79 commit 41c0916
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 8 deletions.
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
Type: Package
Package: councilR
Title: Functions and Templates for the Metropolitan Council
Version: 0.1.5
Date: 2022-11-04
Version: 0.2.0
Date: 2023-03-10
Authors@R: c(
person("Metropolitan Council", role = "cph"),
person("Liz", "Roten", , "liz.roten@metc.state.mn.us", role = c("cre", "aut"),
comment = c(ORCID = "0000-0002-5346-3549")),
person("Ellen", "Esch", , "ellen.esch@metc.state.mn.us", role = "ctb",
comment = c(ORCID = "0000-0002-4253-0910")),
person("Mauricio", "León", , "mauricio.leon@metc.state.mn.us", role = "ctb"),
person("Brandon", "Whited", , "brandon.whited@metc.state.mn.us", role = "ctb"),
person("Garrick", "Aden-Buie", , "garrick@adenbuie.com", role = "ctb",
comment = c(ORCID = "0000-0002-7111-0077"))
)
Expand All @@ -21,6 +22,7 @@ Depends:
R (>= 2.10)
Imports:
cli (>= 3.3.0),
data.table (>= 1.14.6),
DBI (>= 1.1.0),
dplyr (>= 1.0.10),
fs (>= 1.4),
Expand Down Expand Up @@ -59,5 +61,5 @@ Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
Website: https://github.com/Metropolitan-Council/councilR
10 changes: 10 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(fetch_ctu_geo)
export(import_from_emissions)
export(import_from_gis)
export(import_from_gpkg)
export(look)
export(map_council_continuous)
export(scale_color_council)
export(scale_fill_council)
Expand All @@ -21,6 +22,15 @@ importFrom(DBI,dbConnect)
importFrom(DBI,dbDisconnect)
importFrom(DBI,dbGetQuery)
importFrom(cli,cli_abort)
importFrom(data.table,":=")
importFrom(data.table,.BY)
importFrom(data.table,.EACHI)
importFrom(data.table,.GRP)
importFrom(data.table,.I)
importFrom(data.table,.N)
importFrom(data.table,.NGRP)
importFrom(data.table,.SD)
importFrom(data.table,data.table)
importFrom(dplyr,case_when)
importFrom(dplyr,mutate)
importFrom(dplyr,transmute)
Expand Down
9 changes: 9 additions & 0 deletions R/councilR-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,14 @@
"_PACKAGE"
globalVariables(c("colors"))
## usethis namespace: start
#' @importFrom data.table :=
#' @importFrom data.table .BY
#' @importFrom data.table .EACHI
#' @importFrom data.table .GRP
#' @importFrom data.table .I
#' @importFrom data.table .N
#' @importFrom data.table .NGRP
#' @importFrom data.table .SD
#' @importFrom data.table data.table
## usethis namespace: end
NULL
42 changes: 42 additions & 0 deletions R/look.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#' @title Look at data.table subsets
#'
#' @description A function to go into the i statement of a data.table that makes random subsets based on a chosen variable
#'
#' @param var A column from a data.table object
#' @param n numeric, How many values are used in subsetting
#' @param unique logical, Randomly choose from a unique set of levels for subsetting.
#' Otherwise, choose from all values despite potential repetition.
#' @return A logical vector
#'
#' @examples
#' # load some data
#' library(councilR)
#' library(data.table)
#' titanic <- fread("https://raw.githubusercontent.com/Geoyi/Cleaning-Titanic-Data/master/titanic_clean.csv")
#'
#' # look at a random home.dest
#' titanic[look(home.dest)] # re-run the this line for a different random pull
#'
#' # look at a random person
#' titanic[look(name)]
#'
#' # look at a random fare and person of that fare
#' titanic[look(fare)][look(embarked)]
#'
#' @rdname look
#' @export
#'
look <- function(var, n = 1, unique = TRUE) {
argname <- sys.call()[2]
if (unique) {
if (length(var) > 1) {
sampleVar <- sample(unique(var), n)
} else {
sampleVar <- var
}
} else {
sampleVar <- sample(var, n)
}
message(argname, " = ", paste(sampleVar, collapse = ""))
var %in% sampleVar
}
1 change: 0 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

## many functions here come from https://github.com/gadenbuie/js4shiny/blob/master/R/utils.R


Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Please see our contribution guidelines [here](.github/CONTRIBUTING.md).
Thanks to all the folks who have contributed to this project in one way or another

[&#x0040;ashleyasmus](https://github.com/ashleyasmus), [&#x0040;ehesch](https://github.com/ehesch), [&#x0040;eroten](https://github.com/eroten),
[&#x0040;velicknd](https://github.com/velicknd), and [&#x0040;leonx075](https://github.com/leonx075).
[&#x0040;velicknd](https://github.com/velicknd), [&#x0040;Brandon-Whited](https://github.com/Brandon-Whited), and [&#x0040;leonx075](https://github.com/leonx075).



Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ or another
[@ashleyasmus](https://github.com/ashleyasmus),
[@ehesch](https://github.com/ehesch),
[@eroten](https://github.com/eroten),
[@velicknd](https://github.com/velicknd), and
[@velicknd](https://github.com/velicknd),
[@Brandon-Whited](https://github.com/Brandon-Whited), and
[@leonx075](https://github.com/leonx075).
3 changes: 2 additions & 1 deletion man/councilR-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions man/look.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion vignettes/Color.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ cowplot::plot_grid(plotlist = blue_plots)
`scale_color_council()` and `scale_fill_council` will give a color palette starting with `councilBlue`, followed by `cdGreen` and and `mtsRed` and then a couple other council colors which will look decent afterwards (up to 8 levels).

```{r, color-councilpalette}
plot_example +
councilR:::scale_color_council() +
theme_council(use_showtext = F) +
Expand Down

0 comments on commit 41c0916

Please sign in to comment.