Skip to content

Commit

Permalink
remove countrycode_factory and prep 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Jul 15, 2021
1 parent 622ae5f commit 4bf59d6
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 188 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ README.md
LICENSE*
joss
dictionary
.lintr
revdep*
.travis.yml
^.*\.Rproj$
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: countrycode
Title: Convert Country Names and Country Codes
Version: 1.2.0
Date: 2020-05-22
Version: 1.3.0
Date: 2021-07-14
Authors@R:
c(person(given = "Vincent",
family = "Arel-Bundock",
Expand All @@ -23,7 +23,7 @@ Description: Standardize country names, convert them into one of 40
different coding schemes, convert between coding schemes, and assign
region descriptors.
License: GPL-3
URL: https://vincentarelbundock.github.io/countrycode
URL: https://vincentarelbundock.github.io/countrycode/
BugReports: https://github.com/vincentarelbundock/countrycode/issues
Depends:
R (>= 2.10)
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by roxygen2: do not edit by hand

export(countrycode)
export(countrycode_factory)
export(countryname)
export(guess_field)
3 changes: 1 addition & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# countrycode 1.2.0.9000
# countrycode 1.3.0

* new function: countrycode_factory
* destination argument accepts a vector of strings and tries one after the other
* countryname(warn=TRUE) by default
* better class checks
Expand Down
2 changes: 1 addition & 1 deletion R/countrycode.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
#'
#' \dontrun{
#' # Download the dictionary of US states from Github
#' state_dict <- "https://raw.githubusercontent.com/vincentarelbundock/countrycode/main/data/custom_dictionaries/us_states.csv"
#' state_dict <- "https://bit.ly/2ToSrFv"
#' state_dict <- read.csv(state_dict)
#'
#' # The "state.regex" column includes regular expressions, so we set an attribute.
Expand Down
56 changes: 0 additions & 56 deletions R/countrycode_factory.R

This file was deleted.

30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ If you use `countrycode` in your research, we would be very grateful if you coul
- [`custom_match`: Override default values](https://github.com/vincentarelbundock/countrycode#custom_match-override-default-values)
- [`warn`: Silence warnings](https://github.com/vincentarelbundock/countrycode#warn-silence-warnings)
* [`countryname`: Convert country names from any language](https://github.com/vincentarelbundock/countrycode#countryname-convert-country-names-from-any-language)
* [`countrycode_factory`: Custom conversion functions and "crosswalks"](https://github.com/vincentarelbundock/countrycode#countrycode_factory-custom-conversion-functions-and-crosswalks)
* [Contributions](https://github.com/vincentarelbundock/countrycode#contributions)

# Why `countrycode`?
Expand Down Expand Up @@ -353,9 +352,9 @@ The function `countryname` tries to convert country names from any language. For
[1] "ZWE" "AFG" "BRB" "SWE" "GBR" "SGS"
```

# `countrycode_factory`: Custom conversion functions and "crosswalks"
# Custom conversion functions and "crosswalks"

The `countrycode_factory` function allows you to create alternative functions with different default arguments and/or dictionaries. For example, we can create:
It is easy to to create alternative functions with different default arguments and/or dictionaries. For example, we can create:

* `name_to_iso3c` function that sets new defaults for the `origin` and `destination` arguments, and automatically converts country names to iso3c
* `statecode` function to convert US state codes using a custom dictionary by default, that we download from the internet.
Expand All @@ -366,8 +365,12 @@ The `countrycode_factory` function allows you to create alternative functions wi
#################################

# Custom defaults
name_to_iso3c <- countrycode_factory(
origin = "country.name", destination = "iso3c")
name_to_iso3c <- function(sourcevar,
origin = "country.name",
destination = "iso3c",
...) {
countrycode(sourcevar, origin = origin, destination = destination, ...)
}

name_to_iso3c(c("Algeria", "Canada"))
#> [1] "DZA" "CAN"
Expand All @@ -383,11 +386,18 @@ state_dict <- read.csv(state_dict)
# Identify regular expression origin codes
attr(state_dict, "origin_regex") <- "state.regex"

# Set default values for the custom conversion function
statecode <- countrycode_factory(
origin = "state.regex",
destination = "abbreviation",
custom_dict = state_dict)
# Define a custom conversion function
statecode <- function(sourcevar,
origin = "state.regex",
destination = "abbreviation",
custom_dict = state_dict,
...) {
countrycode(sourcevar,
origin = origin,
destination = destination,
custom_dict = custom_dict,
...)
}

# Voilà!
x <- c("Alabama", "New Mexico")
Expand Down
2 changes: 1 addition & 1 deletion man/countrycode.Rd

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

84 changes: 0 additions & 84 deletions man/countrycode_factory.Rd

This file was deleted.

30 changes: 0 additions & 30 deletions tests/testthat/test-factory.R

This file was deleted.

0 comments on commit 4bf59d6

Please sign in to comment.