By default ripeds
allows for non-standard evaluation
(NSE) in the functions. This default setting will feel normal to those
accustomed to working with packages in the Tidyverse. Users can also turn off
NSE with ipeds_init(use_nse = FALSE)
.
Selecting variables
With NSE, variables can be separated by commas without quotation.
NSE
df <- ipeds_init() |>
ipeds_select(instnm, stabbr) |>
ipeds_year(2023) |>
ipeds_get()
df |> head()
#> unitid instnm stabbr year
#> 1 100654 Alabama A & M University AL 2023
#> 2 100663 University of Alabama at Birmingham AL 2023
#> 3 100690 Amridge University AL 2023
#> 4 100706 University of Alabama in Huntsville AL 2023
#> 5 100724 Alabama State University AL 2023
#> 6 100733 University of Alabama System Office AL 2023
Using standard evaluation, quotation and concatenation
c()
is required.
Standard
df <- ipeds_init(use_nse = FALSE) |>
ipeds_select(c("instnm", "stabbr")) |>
ipeds_year(2023) |>
ipeds_get()
df |> head()
#> unitid instnm stabbr year
#> 1 100654 Alabama A & M University AL 2023
#> 2 100663 University of Alabama at Birmingham AL 2023
#> 3 100690 Amridge University AL 2023
#> 4 100706 University of Alabama in Huntsville AL 2023
#> 5 100724 Alabama State University AL 2023
#> 6 100733 University of Alabama System Office AL 2023
Note that with standard evaluation, users can store variables names
in an object and pass the object to ipeds_select()
. This
can be useful with large variable requests or dynamic requests.
## using object
vars_to_get <- c("instnm", "stabbr")
df <- ipeds_init(use_nse = FALSE) |>
ipeds_select(vars_to_get) |>
ipeds_year(2023) |>
ipeds_get()
df |> head()
#> unitid instnm stabbr year
#> 1 100654 Alabama A & M University AL 2023
#> 2 100663 University of Alabama at Birmingham AL 2023
#> 3 100690 Amridge University AL 2023
#> 4 100706 University of Alabama in Huntsville AL 2023
#> 5 100724 Alabama State University AL 2023
#> 6 100733 University of Alabama System Office AL 2023
## dynamically
df_list <- purrr::map(c("instnm", "stabbr", "control"),
~ ipeds_init(use_nse = FALSE) |>
ipeds_select(.x) |>
ipeds_year(2023) |>
ipeds_get())
lapply(df_list, head)
#> [[1]]
#> unitid instnm year
#> 1 100654 Alabama A & M University 2023
#> 2 100663 University of Alabama at Birmingham 2023
#> 3 100690 Amridge University 2023
#> 4 100706 University of Alabama in Huntsville 2023
#> 5 100724 Alabama State University 2023
#> 6 100733 University of Alabama System Office 2023
#>
#> [[2]]
#> unitid stabbr year
#> 1 100654 AL 2023
#> 2 100663 AL 2023
#> 3 100690 AL 2023
#> 4 100706 AL 2023
#> 5 100724 AL 2023
#> 6 100733 AL 2023
#>
#> [[3]]
#> unitid control year
#> 1 100654 1 2023
#> 2 100663 1 2023
#> 3 100690 2 2023
#> 4 100706 1 2023
#> 5 100724 1 2023
#> 6 100733 1 2023
Filters
Filters can also be applied using either NSE or standard evaluation.
With NSE, multiple filters are separated with commas, which are treated
as AND (&
).
NSE
df <- ipeds_init() |>
ipeds_select(instnm, stabbr) |>
ipeds_year(2023) |>
ipeds_filter(stabbr == "KY", control == 1) |> # stabbr == "KY" & control == 1
ipeds_get()
df |> head()
#> unitid year instnm control
#> 1 156231 2023 Ashland Community and Technical College 1
#> 2 156338 2023 Southcentral Kentucky Community and Technical College 1
#> 3 156392 2023 Bluegrass Community and Technical College 1
#> 4 156620 2023 Eastern Kentucky University 1
#> 5 156648 2023 Elizabethtown Community and Technical College 1
#> 6 156790 2023 Hazard Community and Technical College 1
#> stabbr
#> 1 KY
#> 2 KY
#> 3 KY
#> 4 KY
#> 5 KY
#> 6 KY
df |> dplyr::distinct(stabbr, control)
#> stabbr control
#> 1 KY 1
If you want a more complex filter, you will likely need to use standard evaluation.
Standard
df <- ipeds_init(use_nse = FALSE) |>
ipeds_select(c("instnm", "stabbr")) |>
ipeds_year(2023) |>
ipeds_filter("stabbr == 'KY' & (control == 1 | control == 2)") |>
ipeds_get()
df |> head()
#> unitid year instnm control stabbr
#> 1 156189 2023 Alice Lloyd College 2 KY
#> 2 156213 2023 Asbury University 2 KY
#> 3 156222 2023 Asbury Theological Seminary 2 KY
#> 4 156231 2023 Ashland Community and Technical College 1 KY
#> 5 156286 2023 Bellarmine University 2 KY
#> 6 156295 2023 Berea College 2 KY
df |> dplyr::distinct(stabbr, control)
#> stabbr control
#> 1 KY 2
#> 2 KY 1
Note that with ipeds_init(use_nse = FALSE)
you will have
to use standard evaluation throughout the call chain. For more
information about how filters work, see the vignette on filter behavior.