Skip to content

Commit

Permalink
some usethis
Browse files Browse the repository at this point in the history
  • Loading branch information
aedobbyn committed Jun 18, 2018
1 parent ca3fac2 commit 77e5dc2
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 136,476 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
^R/get_all.R$
^R/list_valid_origins.R$
^codecov\.yml$
^LICENSE\.md$
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ sudo: false

cache: packages

r_github_packages:
- r-lib/covr

after_success:
- Rscript -e 'covr::codecov()'

warnings_are_errors: false

r_github_packages:
- jimhester/covr

notifications:
email:
on_success: change
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ Version: 0.1.0
Author: Amanda Dobbyn <[email protected]>
Maintainer: Amanda Dobbyn <[email protected]>
Description: Interface to the United States Postal Service Zone Calc API.
License: GPL (>= 2)
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: TRUE
URL: http://github.com/aedobbyn/usps/
BugReports: https://github.com/aedobbyn/usps/issues/
Imports:
dplyr,
glue,
jsonlite,
knitr,
magrittr,
purrr,
sticky,
stringr,
tibble (>= 1.2),
tidyr
Suggests:
testthat,
Expand Down
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2018
COPYRIGHT HOLDER: Amanda Dobbyn
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT License

Copyright (c) 2018 Amanda Dobbyn

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 0 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(detail_definitions)
export(fetch_all)
export(fetch_five_digit)
export(fetch_zones)
import(magrittr)
importFrom(magrittr,"%>%")
12 changes: 12 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#' All 3-digit zips and zones
#'
#' The result of running fetch_all() with \code{as_range = TRUE}
#'
#' @format A data frame with 136,430 rows and 6 variables:
#' \describe{
#' \item{origin_zip}{price, in US dollars}
#' \item{dest_zip_start}{weight of the diamond, in carats}
#' \item{dest_zip_end}{weight of the diamond, in carats}
#' \item{zone}{weight of the diamond, in carats}
#' }
"zips_zones"
3 changes: 1 addition & 2 deletions R/fetch_all.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#' Grab all the origin-destination pairs.
#'
#' For a given 3-digit origin zip code, grab all destination zips and their corresponding zones.
#'
#' @param origins A vector of origin zips.
#' @param sleep_time How long to sleep in between requests, plus or minus \code{runif(1)} second.
#' @param verbose Message what's going on?
#' @param ... Other arguments
#'
#' @details
#' @details For all the 3-digit origin zip codes, grab all destination zips and their corresponding zones.
#'
#' @importFrom magrittr %>%
#'
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ purrr::map2_dfr(origin_zips, dest_zips,
The USPS zone calc web interface displays zones only as they pertain to destination zip code *ranges*:

<p align="center">
<img src="./img/post_calc.jpg" alt="post_calc" width="70%">
<img src="./man/figures/post_calc.jpg" alt="post_calc" width="70%">
</p>


Expand Down
63 changes: 31 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,59 +51,58 @@ Here we ask for all destination zips for these three origin zips.

If an origin zip is supplied that is [not in
use](https://en.wikipedia.org/wiki/List_of_ZIP_code_prefixes), it is
messaged and included in the output with `NA`s in the other columns.

The origin “004” is not a valid 3-digit zip.
messaged and included in the output with `NA`s in the other columns. For
example, the origin “001” is not a valid 3-digit zip.

``` r
origin_zips <- c("27182818284590", "4", "52353")
origin_zips <- c("1", "271828182845904", "52353")

origin_zips %>%
purrr::map_dfr(fetch_zones)
#> Origin zip 001 is not in use.
#> Warning in prep_zip(.): Zip can be at most 5 characters; trimming
#> 27182818284590 to 27182.
#> Origin zip 004 is not in use.
#> 271828182845904 to 27182.
#> # A tibble: 4,845 x 3
#> origin_zip dest_zip zone
#> <chr> <chr> <chr>
#> 1 271 005 4
#> 2 271 006 7
#> 3 271 007 7
#> 4 271 008 7
#> 5 271 009 7
#> 6 271 010 4
#> 7 271 011 4
#> 8 271 012 4
#> 9 271 013 4
#> 10 271 014 4
#> 1 001 <NA> <NA>
#> 2 271 005 4
#> 3 271 006 7
#> 4 271 007 7
#> 5 271 008 7
#> 6 271 009 7
#> 7 271 010 4
#> 8 271 011 4
#> 9 271 012 4
#> 10 271 013 4
#> # ... with 4,835 more rows
```

Similarly, map over both origin and destination zips and end up at a
dataframe:
dataframe. `verbose` gives you a play-by-play if you want it.

``` r
dest_zips <- c("867", "53", "09")

purrr::map2_dfr(origin_zips, dest_zips,
fetch_zones,
verbose = TRUE)
#> Grabbing origin ZIP 001
#> Origin zip 001 is not in use.
#> Warning in prep_zip(.): Zip can be at most 5 characters; trimming
#> 27182818284590 to 27182.
#> 271828182845904 to 27182.
#> Only 3-character origin zips can be sent to the API. Zip 27182 will be requested as 271.
#> Grabbing origin ZIP 271
#> Recieved 994 destination ZIPs for 8 zones.
#> No zones found for the 271 to 867 pair.
#> Grabbing origin ZIP 004
#> Origin zip 004 is not in use.
#> Only 3-character origin zips can be sent to the API. Zip 52353 will be requested as 523.
#> Grabbing origin ZIP 523
#> Recieved 994 destination ZIPs for 8 zones.
#> # A tibble: 2 x 3
#> # A tibble: 3 x 3
#> origin_zip dest_zip zone
#> <chr> <chr> <chr>
#> 1 004 <NA> <NA>
#> 2 523 009 8
#> 1 001 <NA> <NA>
#> 2 271 053 5
#> 3 523 009 8
```

<br> <br>
Expand All @@ -115,7 +114,7 @@ destination zip code *ranges*:

<p align="center">

<img src="./img/post_calc.jpg" alt="post_calc" width="70%">
<img src="./man/figures/post_calc.jpg" alt="post_calc" width="70%">

</p>

Expand Down Expand Up @@ -161,17 +160,17 @@ detail_definitions %>%
#### The Nitpicky

- Number of digits:
- This API endpoint accepts exactly 3 digit origin zips; it mostly
returns 3 digit destination zips, but notes 5 digit exceptions.
For that reason,
- This API endpoint used in `fetch_zones` accepts exactly 3 digits
for the origin zip; it mostly returns 3 digit destination zips,
but notes 5 digit exceptions. For that reason,
- If fewer than three digits are supplied, leading zeroes are
added with a message
- If more than five digits are supplied, the zip is truncated to
the first five with a warning
- The first three digits of the origin zip are sent to the API
- If destination is supplied, we filter the results to the
first 3 digits if `exact_destination` is `FALSE`; otherwise
we return only the exact destination
- If destination and is 5 digits, `exact_destination`
determines whether we filter to the 5-digit destination only
or include results for the 3-digit destination prefix

<!-- end list -->

Expand All @@ -189,7 +188,7 @@ fetch_zones(origin_zip = "12358132134558",

<br>

#### 5 digits
#### I just want to supply 5 digits

`fetch_zones` should cover most 5 digit cases and supply the most
information when `show_details` is `TRUE`, but if you just want to use
Expand Down
Binary file added data/zip_zones.rda
Binary file not shown.
Loading

0 comments on commit 77e5dc2

Please sign in to comment.