Skip to content

Commit

Permalink
year default changes to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Skinner committed Sep 7, 2018
1 parent 811f00e commit fdd4ebb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion R/get.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ sc_get <- function(sccall, api_key, debug = FALSE, print_key_debug = FALSE) {
## convert names back to non-developer-friendly names and return
if (!sccall[['dfvars']]) {
names(df) <- vapply(names(df), function(x) {
re <- '^[0-9]{0,4}\\.?(' %+% 'academics' %+|%
re <- '^latest|[0-9]{0,4}\\.?(' %+% 'academics' %+|%
'admissions' %+|%
'aid' %+|%
'completion' %+|%
Expand Down
2 changes: 1 addition & 1 deletion R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ sc_init <- function(dfvars = FALSE) {
'select' = NULL,
'filter' = NULL,
'zip' = NULL,
'year' = 2013)
'year' = 'latest')

}
16 changes: 9 additions & 7 deletions R/select_year.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#'
#' @param sccall Current list of parameters carried forward from prior
#' functions in the chain (ignore)
#' @param year Four-digit year (default is 2013)
#' @param year Four-digit year or string \code{latest} for latest data.
#'
#' @section Important notes:
#' \enumerate{
Expand All @@ -22,7 +22,8 @@
#'
#' @examples
#' \dontrun{
#' sc_year()
#' sc_year() # latest
#' sc_year('latest')
#' sc_year(2012)
#' }

Expand All @@ -36,16 +37,17 @@ sc_year <- function(sccall, year) {
call. = FALSE)
}

## can now allow keywork 'latest'

## check second argument
if (missing(year) || !is.numeric(year) || year < 1900 || year > 2099) {
if (missing(year)
|| (!is.character(year) && !is.numeric(year))
|| (is.character(year) && tolower(year) != 'latest')
|| (is.numeric(year) && (year < 1900 || year > 2099))) {
stop('Must provide a 4-digit year in 1900s or 2000s or use the ',
'string \'latest\'', call. = FALSE)
'string \'latest\'.', call. = FALSE)
}

## get vars
sccall[['year']] <- year
sccall[['year']] <- ifelse(is.character(year), tolower(year), year)
sccall

}
Expand Down
5 changes: 3 additions & 2 deletions man/sc_year.Rd

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

0 comments on commit fdd4ebb

Please sign in to comment.