Skip to content

Commit

Permalink
Fixed an error in census_help; added documentation/examples for the d…
Browse files Browse the repository at this point in the history
…ata objects; generated up-to-date Rd files under the man subdirectory
  • Loading branch information
HJ08003 committed Mar 2, 2017
1 parent a3427e2 commit e6707bf
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 50 deletions.
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

export(census_geo_api)
export(census_helper)
export(census_helper_api)
export(census_helper_local)
export(get_census_api)
export(get_census_api_2)
export(get_census_data)
Expand Down
16 changes: 16 additions & 0 deletions R/State.FIPS.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#' State's FIPS.
#'
#' List of States and their FIPS.
#'
#' @format A data frame with 55 rows and 2 variables:
#' \describe{
#' \item{State}{State}
#' \item{FIPS}{FIPS}
#' #' }
#'
#' @docType data
#' @keywords datasets
#' @name State.FIPS
#' @examples
#' data(State.FIPS)
"State.FIPS"
3 changes: 1 addition & 2 deletions R/census_geo_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
#' @examples
#' \dontshow{data(voters)}
#' \dontrun{census_geo_api(key = "...", states = c("NJ", "DE"), geo = "block")}
#' \dontrun{census_geo_api(key = "...", states = "FL", geo = "tract",
#' demo = TRUE)}
#' \dontrun{census_geo_api(key = "...", states = "FL", geo = "tract", demo = TRUE)}
#'
#' @references
#' Relies on get_census_api, get_census_api_2, and vec_to_chunk functions authored by Nicholas Nagle,
Expand Down
9 changes: 4 additions & 5 deletions R/census_helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@
#' @examples
#' \dontshow{data(voters)}
#' \dontrun{census_helper(key = "...", voter.file = voters, states = "nj", geo = "block")}
#' \dontrun{census_helper(key = "...", voter.file = voters, states = "all", geo = "tract",
#' demo = TRUE)}
#' \dontrun{census_helper(key = "...", voter.file = voters, states = "all", geo = "tract", demo = TRUE)}
#'
#' @export
census_helper <- function(key, voter.file, states = "all", geo = "tract", demo = FALSE, census.data = NA) {

if (demo != census.data[[state]]$demo) {
stop(paste("demo = ", demo, " in this function, but demo = ", CensusObj[[state]]$demo, " in census.data object provided.", sep = ""))
}
# if (demo != census.data[[state]]$demo) {
# stop(paste("demo = ", demo, " in this function, but demo = ", CensusObj[[state]]$demo, " in census.data object provided.", sep = ""))
# }

if (is.na(census.data) || (typeof(census.data) != "list")) {
toDownload = TRUE
Expand Down
21 changes: 21 additions & 0 deletions R/pid.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#' Party and race
#'
#' A table for probability of party by race.
#'
#' @format A data frame with 3 rows and 7 variables:
#' \describe{
#' \item{party}{Dem/Rep/Ind}
#' \item{PID}{0/1/2}
#' \item{r_pid_whi}{Pr(PID | White)}
#' \item{r_pid_bla}{Pr(PID | Black)}
#' \item{r_pid_his}{Pr(PID | Hispanic/Latino)}
#' \item{r_pid_asi}{Pr(PID | Asian/Pacific Islander)}
#' \item{r_pid_oth}{Pr(PID | Other)}
#' #' }
#'
#' @docType data
#' @keywords datasets
#' @name pid
#' @examples
#' data(pid)
"pid"
16 changes: 6 additions & 10 deletions R/predict_race.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,14 @@
#'
#' @examples
#' data(voters)
#' predict_race(voters, surname.only = T)
#' predict_race(voters, surname.only = TRUE)
#' predict_race(voter.file = voters, surname.only = TRUE)
#' \dontrun{predict_race(voter.file = voters,
#' census.geo = "tract", census.key = "...", demo = TRUE)}
#' \dontrun{predict_race(voter.file = voters,
#' census.geo = "tract", census.key = "...", party = "PID")}
#' \dontrun{predict_race(voter.file = voters, census.geo = "tract", census.key = "...", demo = TRUE)}
#' \dontrun{predict_race(voter.file = voters, census.geo = "tract", census.key = "...", party = "PID")}
#' \dontrun{CensusObj <- get_census_data("...", state = c("NY", "DC", "NJ"));
#' predict_race(voter.file = voters,
#' census.geo = "tract", census.data = CensusObj, party = "PID")}
#' \dontrun{CensusObj <- get_census_data("...", state = c("NY", "DC", "NJ"), demo = TRUE);
#' predict_race(voter.file = voters,
#' census.geo = "tract", census.data = CensusObj, party = "PID", demo = TRUE)}
#' predict_race(voter.file = voters, census.geo = "tract", census.data = CensusObj, party = "PID")}
#' \dontrun{CensusObj2 <- get_census_data("...", state = c("NY", "DC", "NJ"), demo = TRUE);
#' predict_race(voter.file = voters, census.geo = "tract", census.data = CensusObj2, party = "PID", demo = TRUE)}
#' @export

## Race Prediction Function
Expand Down
6 changes: 6 additions & 0 deletions R/surnames2000.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@
#' \item{p_asi}{Pr(Asian/Pacific Islander | Surname)}
#' \item{p_oth}{Pr(Other | Surname)}
#' #' }
#'
#' @docType data
#' @keywords datasets
#' @name surnames2000
#' @examples
#' data(surnames2000)
"surnames2000"
6 changes: 6 additions & 0 deletions R/surnames2010.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@
#' \item{p_asi}{Pr(Asian/Pacific Islander | Surname)}
#' \item{p_oth}{Pr(Other | Surname)}
#' #' }
#'
#' @docType data
#' @keywords datasets
#' @name surnames
#' @examples
#' data(surnames)
"surnames"
5 changes: 5 additions & 0 deletions R/voters.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@
#' \item{party}{Party registration (character)}
#' \item{PID}{Party registration (numeric)}
#' #' }
#' @docType data
#' @keywords datasets
#' @name voters
#' @examples
#' data(voters)
"voters"
22 changes: 22 additions & 0 deletions man/State.FIPS.Rd

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

3 changes: 1 addition & 2 deletions man/census_geo_api.Rd

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

3 changes: 1 addition & 2 deletions man/census_helper.Rd

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

27 changes: 27 additions & 0 deletions man/pid.Rd

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

16 changes: 6 additions & 10 deletions man/predict_race.Rd

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

3 changes: 3 additions & 0 deletions man/surnames.Rd

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

3 changes: 3 additions & 0 deletions man/surnames2000.Rd

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

44 changes: 27 additions & 17 deletions man/voters.Rd

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

0 comments on commit e6707bf

Please sign in to comment.