vincentarelbundock / countrycode

R package: Convert country names and country codes. Assigns region descriptors.
https://vincentarelbundock.github.io/countrycode
GNU General Public License v3.0
342 stars 83 forks source link

WIP: Function factory #267

Closed vincentarelbundock closed 3 years ago

vincentarelbundock commented 3 years ago

This is a first draft for two new features:

  1. custom_dict can take two attributes: origin_regex and origin_valid. Both must be either NULL (in which case they are ignored) or character vectors. When origin is found in attr(custom_dict, "origin_regex"), the origin_regex is flipped TRUE automatically. When origin is not found in attr(custom_dict, "origin_valid"), we exit with an error.
  2. countrycode_factory is a function factory that allows users to create new functions with different default arguments, or with a default dictionary.

Usage examples are given in the README of the functionfactory branch:

https://github.com/vincentarelbundock/countrycode/tree/functionfactory#custom-dictionary-attributes

This still needs documentation, etc., but I'd be very eager to get feedback on this, if anyone has time to take it for a spin. @cjyetman , maybe?