diff --git a/DESCRIPTION b/DESCRIPTION index 3c8ccb7..3ea0962 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rscorecard Title: A Method to Download Department of Education College Scorecard Data -Version: 0.18.0 +Version: 0.19.0 Authors@R: person("Benjamin", "Skinner", email = "btskinner@coe.ufl.edu", role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index e0b82ab..3a9617b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# v0.19.0 + +- update to only allow filtering on variables allowed due to API + changes on 4 April 2021 + # v0.18.0 - update dictionary for 12 January 2021 release of data diff --git a/R/dictionary.R b/R/dictionary.R index daf5a28..17f6e0c 100644 --- a/R/dictionary.R +++ b/R/dictionary.R @@ -24,6 +24,12 @@ #' @param return_df Return a tibble of the subset data dictionary. #' @param print_off Do not print to console; useful if you only want #' to return a tibble of dictionary values. +#' @param can_filter Use to confirm that a variable can be used as a +#' filtering variable. Returns \code{TRUE} or \code{FALSE} +#' @param filter_vars Use to print variables that can be used to +#' filter calls. Use with argument \code{return_df = TRUE} to +#' return a tibble of these variables in addition to console +#' output. #' #' @examples #' ## simple search for 'state' in any part of the dictionary @@ -35,6 +41,9 @@ #' ## return full dictionary (only recommended if not printing and #' ## storing in object) #' df <- sc_dict('.', limit = Inf, print_off = TRUE, return_df = TRUE) +#' +#' ## print list of variables that can be used to filter +#' df <- sc_dict('.', filter_vars = TRUE, return_df = TRUE) #' @export sc_dict <- function(search_string, @@ -47,13 +56,43 @@ sc_dict <- function(search_string, 'source'), ignore_case = TRUE, limit = 10, confirm = FALSE, print_dev = FALSE, print_notes = FALSE, - return_df = FALSE, print_off = FALSE) { + return_df = FALSE, print_off = FALSE, + can_filter = FALSE, filter_vars = FALSE) { ## only for confirm if (confirm) { return(!is.null(sc_hash[[search_string]])) } + ## only for can_filter + if (can_filter) { + ## NB: using any() to be TRUE if any TRUE + return(any(dict[["can_filter"]][dict[["varname"]] == search_string] == 1)) + } + + ## print filter variables + if (filter_vars) { + out <- dict[dict[["can_filter"]] == 1,] + uniqv <- sort(unique(out[["varname"]])) + ## console table + cat('\n' %+% paste(rep('', 70), collapse = '-') %+% '\n') + cat('The following variables can be used in sc_filter():') + cat('\n' %+% paste(rep('', 70), collapse = '-') %+% '\n\n') + for (i in 1:length(uniqv)) { + cat(' - ' %+% uniqv[i] %+% '\n') + } + if (return_df) { + cat('\n') + var_order <- c('varname', 'value', 'label', 'description', 'source', + 'dev_friendly_name', 'dev_category', 'notes', 'can_filter') + out <- tidyr::as_tibble(out) %>% + dplyr::select(dplyr::one_of(var_order)) + return(out) + } else { + return(cat('\n')) + } + } + ## get values if (match.arg(search_col) == 'all') { rows <- rep(FALSE, nrow(dict)) @@ -126,7 +165,12 @@ sc_dict <- function(search_string, } cat('\n') } - + cat('CAN FILTER? ') + if (d[['can_filter']][[1]] == 1) { + cat('Yes\n\n') + } else { + cat('No\n\n') + } } cat(paste(rep('', 70), collapse = '-') %+% '\n') @@ -138,10 +182,12 @@ sc_dict <- function(search_string, ## return_df ? return (out) : <> if (return_df) { - var_order <- c('varname', 'value', 'label', 'description', 'source', - 'dev_friendly_name', 'dev_category', 'notes') - out <- tidyr::as_tibble(out) %>% - dplyr::select(dplyr::one_of(var_order)) - return(out) + var_order <- c('varname', 'value', 'label', 'description', 'source', + 'dev_friendly_name', 'dev_category', 'notes', 'can_filter') + out <- tidyr::as_tibble(out) %>% + dplyr::select(dplyr::one_of(var_order)) + return(out) } + + } diff --git a/R/filter.R b/R/filter.R index c1fbb48..7f2ad3a 100644 --- a/R/filter.R +++ b/R/filter.R @@ -72,6 +72,13 @@ sc_filter_ <- function(sccall, filter_string) { stop('Must use either \"==\", \"!=\", or \"%in%\" in sc_filter.', call. = FALSE) } + if (!sc_dict(tolower(as.character(filter[[i]][[2]])), can_filter = TRUE)) { + stop('The variable \"' %+% filter[[i]][[2]] + %+% '\" cannot be used as filter. ' + %+% 'Revise your call to remove this filtering variable.\n' + %+% 'Use sc_dict(filter_vars = TRUE) to see available filters.', + call. = FALSE) + } if (!sc_dict(tolower(as.character(filter[[i]][[2]])), confirm = TRUE)) { stop('Variable \"' %+% filter[[i]][[2]] %+% '\" not found in dictionary. ' diff --git a/R/sysdata.rda b/R/sysdata.rda index b6d30be..2b1576c 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/README.md b/README.md index e0a88a4..1435a47 100644 --- a/README.md +++ b/README.md @@ -55,12 +55,12 @@ key in your R environment at the start of your R session using ## # A tibble: 6 x 4 ## unitid instnm stabbr year ## - ## 1 214625 Pennsylvania State University-Penn State New Kensington PA latest - ## 2 196051 SUNY Morrisville NY latest - ## 3 194392 Paul Smiths College of Arts and Science NY latest - ## 4 214643 Pennsylvania State University-Penn State Wilkes-Barre PA latest - ## 5 191676 Houghton College NY latest - ## 6 197230 Wells College NY latest + ## 1 191676 Houghton College NY latest + ## 2 194392 Paul Smiths College of Arts and Science NY latest + ## 3 196051 SUNY Morrisville NY latest + ## 4 197230 Wells College NY latest + ## 5 214625 Pennsylvania State University-Penn State New Kensington PA latest + ## 6 214643 Pennsylvania State University-Penn State Wilkes-Barre PA latest For more example calls and information about other package commands, see the [extended @@ -91,6 +91,8 @@ function. ## 3 = Private for-profit ## 4 = Foreign ## + ## CAN FILTER? Yes + ## ## ## --------------------------------------------------------------------- ## varname: schtype source: FSA @@ -105,6 +107,8 @@ function. ## 2 = Private, Nonprofit ## 3 = Proprietary ## + ## CAN FILTER? No + ## ## --------------------------------------------------------------------- ## Printed information for 2 of out 2 variables. diff --git a/data-raw/make_dict_hash.R b/data-raw/make_dict_hash.R index 5dd2863..a06d73b 100644 --- a/data-raw/make_dict_hash.R +++ b/data-raw/make_dict_hash.R @@ -14,9 +14,9 @@ sheets <- c("institution_data_dictionary", ## read in each sheet, munge, and bind df <- purrr::map(sheets, - ~ read_excel(file, sheet = .x) %>% + ~ read_excel(file, sheet = .x) |> ## lower names - setNames(tolower(names(.))) %>% + rename_all(tolower) |> ## subset/rename select(description = `name of data element`, dev_category = `dev-category`, @@ -25,27 +25,39 @@ df <- purrr::map(sheets, value, label, source, - notes) %>% + notes, + can_filter = index) |> ## lower name values for varname column - mutate(varname = tolower(varname)) %>% + mutate(varname = tolower(varname)) |> ## remove extra \r\n from description column - mutate(description = gsub("^(.+)\r\n 0.*$", "\\1", description)) %>% + mutate(description = gsub("^(.+)\r\n 0.*$", "\\1", description)) |> ## remove trailing characters from dev_friendly_name mutate(dev_friendly_name = gsub("^(.+):$", "\\1", - dev_friendly_name)) %>% + dev_friendly_name)) |> + ## convert can_filter column to 1 if there's text there + mutate(can_filter = ifelse(!is.na(can_filter), 1, can_filter), + ## fix unitid can_filter to 1 since it works for filtering + can_filter = ifelse(varname == "unitid", 1, can_filter), + ## convert to integer + can_filter = as.integer(can_filter)) |> ## roll values forward to fill NA mutate(description = na.locf(description), dev_category = na.locf(dev_category), dev_friendly_name = na.locf(dev_friendly_name), varname = na.locf(varname), source = na.locf(source), - notes = na.locf(notes)) - ) %>% + notes = na.locf(notes)) |> + ## roll values forward in can_filter, grouped by variable name + group_by(varname) |> + mutate(can_filter = na.locf(can_filter, na.rm = FALSE)) |> + ungroup() |> + mutate(can_filter = ifelse(is.na(can_filter), 0, can_filter)) + ) |> ## bind together - bind_rows + bind_rows() ## make dictionary data frame -dict <- df %>% data.frame(.) +dict <- df |> data.frame() ## create hash environment for quick conversion between varnames ## and developer-friendly names @@ -55,7 +67,7 @@ sc_hash <- new.env(parent = emptyenv()) ## (1) varname <- dev_friendly ## (2) varname_c <- root -tmp <- df %>% distinct(varname, .keep_all = TRUE) +tmp <- df |> distinct(varname, .keep_all = TRUE) for (i in 1:nrow(tmp)) { ## key/value pair (1) @@ -72,7 +84,7 @@ for (i in 1:nrow(tmp)) { ## (3) dev_friendly <- varname ## (4) dev_friendly_c <- root -tmp <- df %>% distinct(dev_friendly_name, .keep_all = TRUE) +tmp <- df |> distinct(dev_friendly_name, .keep_all = TRUE) for (i in 1:nrow(tmp)) { ## key/value pair (3) @@ -96,8 +108,8 @@ for (i in 1:nrow(tmp)) { ## the information will continue to come from the institution data both_sources <- c("unitid", "opeid6", "control", "main", "instnm") -tmp <- df %>% - filter(varname %in% both_sources) %>% +tmp <- df |> + filter(varname %in% both_sources) |> distinct(dev_category, varname, .keep_all = TRUE) for (i in 1:nrow(tmp)) { diff --git a/docs/404.html b/docs/404.html index 543ed7f..6381a3f 100644 --- a/docs/404.html +++ b/docs/404.html @@ -79,7 +79,7 @@ rscorecard - 0.17.0 + 0.19.0 @@ -125,7 +125,7 @@
  • - + twitter diff --git a/docs/CODE_OF_CONDUCT.html b/docs/CODE_OF_CONDUCT.html index de0e348..710bfbb 100644 --- a/docs/CODE_OF_CONDUCT.html +++ b/docs/CODE_OF_CONDUCT.html @@ -79,7 +79,7 @@ rscorecard - 0.17.0 + 0.19.0 @@ -125,7 +125,7 @@
  • - + twitter diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 9ff1413..65bf2a7 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -79,7 +79,7 @@ rscorecard - 0.17.0 + 0.19.0 @@ -125,7 +125,7 @@
  • - + twitter diff --git a/docs/articles/commands.html b/docs/articles/commands.html index 3e474eb..bc912f9 100644 --- a/docs/articles/commands.html +++ b/docs/articles/commands.html @@ -38,7 +38,7 @@ rscorecard - 0.17.0 + 0.19.0 @@ -84,7 +84,7 @@
  • - + twitter @@ -99,13 +99,12 @@ - -
    +

    You can also search using regular expressions and limit the search to only one dictionary column. For example, the search below only looks for varnames starting with “st”:

    @@ -249,6 +250,8 @@

    #> #> VALUES: NA #> +#> CAN FILTER? Yes +#> #> #> --------------------------------------------------------------------- #> varname: st_fips source: IPEDS @@ -318,21 +321,24 @@

    #> 72 = Puerto Rico #> 78 = Virgin Islands #> +#> CAN FILTER? Yes +#> #> --------------------------------------------------------------------- #> Printed information for 2 of out 2 variables.

    You can also return the data dictionary as a tibble. When storing the dictionary in an object, it may be useful to set print_off = TRUE so that the dictionary results don’t print to the console:

     dict_df <- sc_dict('stabbr', print_off = TRUE, return_df = TRUE)
     dict_df
    -#> # A tibble: 1 x 8
    +#> # A tibble: 1 x 9
     #>   varname value label description  source dev_friendly_na… dev_category notes   
     #>   <chr>   <dbl> <chr> <chr>        <chr>  <chr>            <chr>        <chr>   
    -#> 1 stabbr     NA <NA>  State postc… IPEDS  state            school       Shown/u…
    +#> 1 stabbr NA <NA> State postc… IPEDS state school Shown/u… +#> # … with 1 more variable: can_filter <dbl>

    If you want the full data dictionary, simply search for '.':

     dict_df <- sc_dict('.', print_off = TRUE, return_df = TRUE)
     dict_df
    -#> # A tibble: 2,395 x 8
    +#> # A tibble: 2,743 x 9
     #>    varname  value label description  source dev_friendly_na… dev_category notes 
     #>    <chr>    <dbl> <chr> <chr>        <chr>  <chr>            <chr>        <chr> 
     #>  1 unitid      NA <NA>  Unit ID for… IPEDS  id               root         Shown…
    @@ -345,7 +351,7 @@ 

    #> 8 accreda… NA <NA> Accreditor … FSA accreditor school Shown… #> 9 insturl NA <NA> URL for ins… IPEDS school_url school Shown… #> 10 npcurl NA <NA> URL for ins… IPEDS price_calculato… school Shown… -#> # … with 2,385 more rows

    +#> # … with 2,733 more rows, and 1 more variable: can_filter <dbl>
    diff --git a/docs/articles/commands_files/header-attrs-2.9/header-attrs.js b/docs/articles/commands_files/header-attrs-2.9/header-attrs.js new file mode 100644 index 0000000..dd57d92 --- /dev/null +++ b/docs/articles/commands_files/header-attrs-2.9/header-attrs.js @@ -0,0 +1,12 @@ +// Pandoc 2.9 adds attributes on both header and div. We remove the former (to +// be compatible with the behavior of Pandoc < 2.8). +document.addEventListener('DOMContentLoaded', function(e) { + var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); + var i, h, a; + for (i = 0; i < hs.length; i++) { + h = hs[i]; + if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 + a = h.attributes; + while (a.length > 0) h.removeAttribute(a[0].name); + } +}); diff --git a/docs/articles/index.html b/docs/articles/index.html index ee6838d..ac0402a 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -79,7 +79,7 @@ rscorecard - 0.17.0 + 0.19.0 @@ -125,7 +125,7 @@
  • - + twitter diff --git a/docs/articles/introduction_files/header-attrs-2.9/header-attrs.js b/docs/articles/introduction_files/header-attrs-2.9/header-attrs.js new file mode 100644 index 0000000..dd57d92 --- /dev/null +++ b/docs/articles/introduction_files/header-attrs-2.9/header-attrs.js @@ -0,0 +1,12 @@ +// Pandoc 2.9 adds attributes on both header and div. We remove the former (to +// be compatible with the behavior of Pandoc < 2.8). +document.addEventListener('DOMContentLoaded', function(e) { + var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); + var i, h, a; + for (i = 0; i < hs.length; i++) { + h = hs[i]; + if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 + a = h.attributes; + while (a.length > 0) h.removeAttribute(a[0].name); + } +}); diff --git a/docs/articles/more_examples_files/header-attrs-2.9/header-attrs.js b/docs/articles/more_examples_files/header-attrs-2.9/header-attrs.js new file mode 100644 index 0000000..dd57d92 --- /dev/null +++ b/docs/articles/more_examples_files/header-attrs-2.9/header-attrs.js @@ -0,0 +1,12 @@ +// Pandoc 2.9 adds attributes on both header and div. We remove the former (to +// be compatible with the behavior of Pandoc < 2.8). +document.addEventListener('DOMContentLoaded', function(e) { + var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); + var i, h, a; + for (i = 0; i < hs.length; i++) { + h = hs[i]; + if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 + a = h.attributes; + while (a.length > 0) h.removeAttribute(a[0].name); + } +}); diff --git a/docs/authors.html b/docs/authors.html index a38537a..56c24a8 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -79,7 +79,7 @@ rscorecard - 0.17.0 + 0.19.0 @@ -125,7 +125,7 @@
  • - + twitter diff --git a/docs/index.html b/docs/index.html index 0a1f325..c8a87b9 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ rscorecard - 0.17.0 + 0.19.0 @@ -89,7 +89,7 @@
  • - + twitter @@ -147,14 +147,14 @@

    df ## # A tibble: 6 x 4 -## instnm stabbr unitid year -## <chr> <chr> <int> <chr> -## 1 SUNY Morrisville NY 196051 latest -## 2 Pennsylvania State University-Penn State New Kensington PA 214625 latest -## 3 Paul Smiths College of Arts and Science NY 194392 latest -## 4 Houghton College NY 191676 latest -## 5 Pennsylvania State University-Penn State Wilkes-Barre PA 214643 latest -## 6 Wells College NY 197230 latest +## unitid instnm stabbr year +## <int> <chr> <chr> <chr> +## 1 191676 Houghton College NY latest +## 2 194392 Paul Smiths College of Arts and Science NY latest +## 3 196051 SUNY Morrisville NY latest +## 4 197230 Wells College NY latest +## 5 214625 Pennsylvania State University-Penn State New Kensington PA latest +## 6 214643 Pennsylvania State University-Penn State Wilkes-Barre PA latest

    For more example calls and information about other package commands, see the extended vignette.

    @@ -181,22 +181,26 @@

    ## 3 = Private for-profit ## 4 = Foreign ## -## -## --------------------------------------------------------------------- -## varname: schtype source: FSA +## CAN FILTER? Yes +## +## ## --------------------------------------------------------------------- -## DESCRIPTION: -## -## Control of institution, per PEPS +## varname: schtype source: FSA +## --------------------------------------------------------------------- +## DESCRIPTION: ## -## VALUES: +## Control of institution, per PEPS ## -## 1 = Public -## 2 = Private, Nonprofit -## 3 = Proprietary -## -## --------------------------------------------------------------------- -## Printed information for 2 of out 2 variables.

    +## VALUES: +## +## 1 = Public +## 2 = Private, Nonprofit +## 3 = Proprietary +## +## CAN FILTER? No +## +## --------------------------------------------------------------------- +## Printed information for 2 of out 2 variables.
    @@ -254,7 +258,7 @@

    Developers

    Dev status

      -
    • Build Status
    • +
    • R build status
    • GitHub release
    • CRAN_Status_Badge
    diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 24935c7..802f1ea 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -1,11 +1,11 @@ -pandoc: 2.11.2 +pandoc: 2.14.0.3 pkgdown: 1.6.1 pkgdown_sha: ~ articles: commands: commands.html introduction: introduction.html more_examples: more_examples.html -last_built: 2020-12-03T22:48Z +last_built: 2021-07-12T21:22Z urls: reference: https://www.btskinner.io/rscorecard//reference article: https://www.btskinner.io/rscorecard//articles diff --git a/docs/reference/index.html b/docs/reference/index.html index 3dae04e..8094d29 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -79,7 +79,7 @@ rscorecard - 0.17.0 + 0.19.0
    @@ -125,7 +125,7 @@

  • - + twitter diff --git a/docs/reference/reexports.html b/docs/reference/reexports.html index ccd4ea2..632111a 100644 --- a/docs/reference/reexports.html +++ b/docs/reference/reexports.html @@ -85,7 +85,7 @@ rscorecard - 0.17.0 + 0.19.0 @@ -131,7 +131,7 @@
  • - + twitter diff --git a/docs/reference/rscorecard.html b/docs/reference/rscorecard.html index 4e65f32..e902091 100644 --- a/docs/reference/rscorecard.html +++ b/docs/reference/rscorecard.html @@ -86,7 +86,7 @@ rscorecard - 0.17.0 + 0.19.0 @@ -132,7 +132,7 @@
  • - + twitter diff --git a/docs/reference/sc_dict.html b/docs/reference/sc_dict.html index 5ec4133..a639e71 100644 --- a/docs/reference/sc_dict.html +++ b/docs/reference/sc_dict.html @@ -81,7 +81,7 @@ rscorecard - 0.17.0 + 0.19.0 @@ -127,7 +127,7 @@
  • - + twitter @@ -165,7 +165,9 @@

    Search data dictionary.

    print_dev = FALSE, print_notes = FALSE, return_df = FALSE, - print_off = FALSE + print_off = FALSE, + can_filter = FALSE, + filter_vars = FALSE )

    Arguments

    @@ -218,6 +220,18 @@

    Arg print_off

    Do not print to console; useful if you only want to return a tibble of dictionary values.

    + + + can_filter +

    Use to confirm that a variable can be used as a +filtering variable. Returns TRUE or FALSE

    + + + filter_vars +

    Use to print variables that can be used to +filter calls. Use with argument return_df = TRUE to +return a tibble of these variables in addition to console +output.

    @@ -235,6 +249,8 @@

    Examp #> #> VALUES: NA #> +#> CAN FILTER? Yes +#> #> #> --------------------------------------------------------------------- #> varname: st_fips source: IPEDS @@ -304,6 +320,8 @@

    Examp #> 72 = Puerto Rico #> 78 = Virgin Islands #> +#> CAN FILTER? Yes +#> #> #> --------------------------------------------------------------------- #> varname: tuitionfee_in source: IPEDS @@ -314,6 +332,8 @@

    Examp #> #> VALUES: NA #> +#> CAN FILTER? Yes +#> #> #> --------------------------------------------------------------------- #> varname: tuitionfee_out source: IPEDS @@ -324,6 +344,8 @@

    Examp #> #> VALUES: NA #> +#> CAN FILTER? Yes +#> #> --------------------------------------------------------------------- #> Printed information for 4 of out 4 variables. #>
    @@ -339,6 +361,8 @@

    Examp #> #> VALUES: NA #> +#> CAN FILTER? Yes +#> #> #> --------------------------------------------------------------------- #> varname: st_fips source: IPEDS @@ -408,13 +432,74 @@

    Examp #> 72 = Puerto Rico #> 78 = Virgin Islands #> +#> CAN FILTER? Yes +#> #> --------------------------------------------------------------------- #> Printed information for 2 of out 2 variables. #>

    ## return full dictionary (only recommended if not printing and ## storing in object) df <- sc_dict('.', limit = Inf, print_off = TRUE, return_df = TRUE) -
    + +## print list of variables that can be used to filter +df <- sc_dict('.', filter_vars = TRUE, return_df = TRUE) +
    #> +#> --------------------------------------------------------------------- +#> The following variables can be used in sc_filter(): +#> --------------------------------------------------------------------- +#> +#> - aanapii +#> - actcmmid +#> - adm_rate +#> - annhi +#> - ccbasic +#> - cipcode +#> - city +#> - cntover150_3yr +#> - control +#> - creddesc +#> - credlev +#> - curroper +#> - debt_all_stgp_any_mdn +#> - earn_mdn_hi_2yr +#> - fedschcd +#> - gt_25k_p6 +#> - hbcu +#> - hcm2 +#> - highdeg +#> - hsi +#> - instnm +#> - insturl +#> - ipedscount1 +#> - ipedscount2 +#> - locale +#> - locale2 +#> - main +#> - md_earn_wne_p10 +#> - menonly +#> - mn_earn_wne_inc1_p6 +#> - nanti +#> - numbranch +#> - opeid +#> - opeid6 +#> - pbi +#> - preddeg +#> - region +#> - relaffil +#> - sat_avg +#> - satmtmid +#> - satvrmid +#> - satwrmid +#> - st_fips +#> - stabbr +#> - tribal +#> - tuitionfee_in +#> - tuitionfee_out +#> - ugds +#> - unitid +#> - womenonly +#> - zip +#>
    @@ -127,7 +127,7 @@

  • - + twitter diff --git a/docs/reference/sc_get.html b/docs/reference/sc_get.html index 8d49ab0..faab5d5 100644 --- a/docs/reference/sc_get.html +++ b/docs/reference/sc_get.html @@ -82,7 +82,7 @@ rscorecard - 0.17.0 + 0.19.0 @@ -128,7 +128,7 @@
  • - + twitter diff --git a/docs/reference/sc_init.html b/docs/reference/sc_init.html index f1b3462..807188a 100644 --- a/docs/reference/sc_init.html +++ b/docs/reference/sc_init.html @@ -81,7 +81,7 @@ rscorecard - 0.17.0 + 0.19.0 @@ -127,7 +127,7 @@
  • - + twitter diff --git a/docs/reference/sc_key.html b/docs/reference/sc_key.html index f2a1701..f4f6e78 100644 --- a/docs/reference/sc_key.html +++ b/docs/reference/sc_key.html @@ -83,7 +83,7 @@ rscorecard - 0.17.0 + 0.19.0 @@ -129,7 +129,7 @@
  • - + twitter diff --git a/docs/reference/sc_select.html b/docs/reference/sc_select.html index 1cc5e5a..848f754 100644 --- a/docs/reference/sc_select.html +++ b/docs/reference/sc_select.html @@ -80,7 +80,7 @@ rscorecard - 0.17.0 + 0.19.0 @@ -126,7 +126,7 @@
  • - + twitter diff --git a/docs/reference/sc_year.html b/docs/reference/sc_year.html index a7122fc..e67a8b1 100644 --- a/docs/reference/sc_year.html +++ b/docs/reference/sc_year.html @@ -80,7 +80,7 @@ rscorecard - 0.17.0 + 0.19.0 @@ -126,7 +126,7 @@
  • - + twitter diff --git a/docs/reference/sc_zip.html b/docs/reference/sc_zip.html index 395c7c1..612ba29 100644 --- a/docs/reference/sc_zip.html +++ b/docs/reference/sc_zip.html @@ -80,7 +80,7 @@ rscorecard - 0.17.0 + 0.19.0 @@ -126,7 +126,7 @@
  • - + twitter diff --git a/man/sc_dict.Rd b/man/sc_dict.Rd index 9cc67f0..046a48f 100644 --- a/man/sc_dict.Rd +++ b/man/sc_dict.Rd @@ -14,7 +14,9 @@ sc_dict( print_dev = FALSE, print_notes = FALSE, return_df = FALSE, - print_off = FALSE + print_off = FALSE, + can_filter = FALSE, + filter_vars = FALSE ) } \arguments{ @@ -47,6 +49,14 @@ included in the data dictionary (if any).} \item{print_off}{Do not print to console; useful if you only want to return a tibble of dictionary values.} + +\item{can_filter}{Use to confirm that a variable can be used as a +filtering variable. Returns \code{TRUE} or \code{FALSE}} + +\item{filter_vars}{Use to print variables that can be used to +filter calls. Use with argument \code{return_df = TRUE} to +return a tibble of these variables in addition to console +output.} } \description{ This function is used to search the College Scorecard @@ -62,4 +72,7 @@ sc_dict('^st', search_col = 'varname') ## return full dictionary (only recommended if not printing and ## storing in object) df <- sc_dict('.', limit = Inf, print_off = TRUE, return_df = TRUE) + +## print list of variables that can be used to filter +df <- sc_dict('.', filter_vars = TRUE, return_df = TRUE) } diff --git a/tests/testthat/test-dictionary.R b/tests/testthat/test-dictionary.R index e9ef201..40dba20 100644 --- a/tests/testthat/test-dictionary.R +++ b/tests/testthat/test-dictionary.R @@ -10,7 +10,8 @@ test_that('Dictionary does not return correct object', { source = 'IPEDS', dev_friendly_name = 'state', dev_category = 'school', - notes = 'Shown/used on consumer website.') + notes = 'Shown/used on consumer website.', + can_filter = 1) df2 <- sc_dict('stabbr', return_df = TRUE, print_off = TRUE) @@ -45,7 +46,8 @@ test_that('Dictionary does not return correct object', { source = 'IPEDS', dev_friendly_name = 'state_fips', dev_category = 'school', - notes = 'Shown/used on consumer website.') + notes = 'Shown/used on consumer website.', + can_filter = 1) df2 <- sc_dict('st_fips', return_df = TRUE, print_off = TRUE) diff --git a/tests/testthat/test-filter.R b/tests/testthat/test-filter.R index c6fe0f3..0e0aaec 100644 --- a/tests/testthat/test-filter.R +++ b/tests/testthat/test-filter.R @@ -88,3 +88,8 @@ test_that('Filtered pulls not the same', { expect_equal(df1, df2) }) + +test_that('Allows for filter variable that is not approved', { + check_api() + expect_error(sc_filter(dil, avgfacsal == 100000)) +}) diff --git a/vignettes/introduction.Rmd b/vignettes/introduction.Rmd index ba98f3f..9abde1d 100644 --- a/vignettes/introduction.Rmd +++ b/vignettes/introduction.Rmd @@ -38,7 +38,7 @@ which will persist until the R session is closed. ```{r, eval = FALSE} # NB: You must use a real key, of course... -sc_key('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') +sc_key("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") ``` If you want a more permanent solution, you can add the following line @@ -51,7 +51,7 @@ for more information. DATAGOV_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ``` -## Simple request +## 2. Simple request Each request requires the following four commands piped together using `%>%`: @@ -86,7 +86,7 @@ returned. We could have specifically asked for the latest data using df <- sc_init() %>% sc_filter(region == 2, ccbasic == c(21,22,23), locale == 41:43) %>% sc_select(unitid, instnm, stabbr, ugds) %>% - sc_year('latest') %>% + sc_year("latest") %>% sc_get() ``` ```{r}