-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c834751
commit c3cf8ef
Showing
95 changed files
with
703 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Type: Package | ||
Package: MazamaSpatialUtils | ||
Version: 0.8.6 | ||
Version: 0.8.7 | ||
Title: Spatial Data Download and Utility Functions | ||
Authors@R: c( | ||
person("Jonathan", "Callahan", email="[email protected]", role=c("aut","cre")), | ||
|
@@ -57,4 +57,4 @@ Suggests: | |
Encoding: UTF-8 | ||
VignetteBuilder: knitr | ||
LazyData: true | ||
RoxygenNote: 7.2.3 | ||
RoxygenNote: 7.3.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#' | ||
#' @name countryConversion | ||
#' @aliases countryCodeToName countryCodeToFIPS | ||
#' @aliases countryFIPSToName countryCodeToCode | ||
#' @aliases countryNameToCode countryNameToFIPS | ||
#' | ||
#' @title Conversion functions for country names, codes and FIPS codes. | ||
#' | ||
#' @param countryName Vector of English language country names. | ||
#' @param countryCode Vector of ISO 3166-1 alpha-2 codes. | ||
#' @param countryFIPS Vector of two-character FIPS codes. | ||
#' | ||
#' @return A vector of country names or codes. | ||
#' | ||
#' @description Converts a vector of country names or codes from one system to | ||
#' another returning \code{NA} where no match is found. | ||
#' | ||
#' @examples | ||
#' library(MazamaSpatialUtils) | ||
#' | ||
#' # FIPS codes are different! | ||
#' | ||
#' countryNameToCode("Germany") | ||
#' countryNameToFIPS("Germany") | ||
#' | ||
#' countryCodeToName("CH") | ||
#' countryFIPSToName("CH") | ||
#' | ||
#' countryCodes <- sample(SimpleCountries$countryCode, 30) | ||
#' | ||
#' data.frame( | ||
#' name = countryCodeToName(countryCodes), | ||
#' code = countryCodes, | ||
#' FIPS = countryCodeToFIPS(countryCodes) | ||
#' ) | ||
#' | ||
NULL | ||
|
||
#' @rdname countryConversion | ||
#' @export | ||
countryCodeToName <- function( | ||
countryCode = NULL | ||
) { | ||
countryName <- countrycode::countrycode( | ||
countryCode, "iso2c", "country.name", | ||
custom_match = c("AN" = "Netherlands Antilles") # custom match for Netherlands Antilles | ||
) | ||
return(countryName) | ||
} | ||
|
||
#' @rdname countryConversion | ||
#' @export | ||
countryCodeToFIPS <- function( | ||
countryCode = NULL | ||
) { | ||
values <- MazamaSpatialUtils::SimpleCountries$FIPS | ||
names(values) <- toupper(MazamaSpatialUtils::SimpleCountries$countryCode) | ||
return( as.character(values[toupper(countryCode)]) ) | ||
} | ||
|
||
#' @rdname countryConversion | ||
#' @export | ||
countryFIPSToName <- function( | ||
countryFIPS = NULL | ||
) { | ||
countryName <- countryFIPS %>% countryFIPSToCode() %>% countryCodeToName() | ||
return(countryName) | ||
} | ||
|
||
#' @rdname countryConversion | ||
#' @export | ||
countryFIPSToCode <- function( | ||
countryFIPS = NULL | ||
) { | ||
values <- MazamaSpatialUtils::SimpleCountries$countryCode | ||
names(values) <- toupper(MazamaSpatialUtils::SimpleCountries$FIPS) | ||
return( as.character(values[toupper(countryFIPS)]) ) | ||
} | ||
|
||
#' @rdname countryConversion | ||
#' @export | ||
countryNameToCode <- function( | ||
countryName = NULL | ||
) { | ||
countryCode <- countrycode::countrycode( | ||
countryName, "country.name", "iso2c", | ||
custom_match = c("Netherlands Antilles" = "AN") # custom match for Netherlands Antilles | ||
) | ||
return(countryCode) | ||
} | ||
|
||
#' @rdname countryConversion | ||
#' @export | ||
countryNameToFIPS <- function( | ||
countryName = NULL | ||
) { | ||
countryFIPS <- countryName %>% countryNameToCode() %>% countryCodeToFIPS() | ||
return(countryFIPS) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.