Skip to content

Commit

Permalink
version 1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
fbellelli authored and cran-robot committed Oct 6, 2023
1 parent 624a030 commit d65a909
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 137 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: countries
Type: Package
Title: Deal with Country Data in an Easy Way
Version: 1.0.4
Version: 1.0.5
Authors@R:
person("Francesco Saverio", "Bellelli", , "fsabellelli@gmail.com", role = c("aut", "cre", "cph"),
comment = c(Website = "https://fbellelli.com/"))
Expand All @@ -24,8 +24,8 @@ BugReports: https://github.com/fbellelli/countries/issues
Config/testthat/edition: 3
LazyData: true
NeedsCompilation: no
Packaged: 2023-09-24 16:51:15 UTC; FSB
Packaged: 2023-10-05 21:25:55 UTC; FSB
Author: Francesco Saverio Bellelli [aut, cre, cph] (https://fbellelli.com/)
Maintainer: Francesco Saverio Bellelli <fsabellelli@gmail.com>
Repository: CRAN
Date/Publication: 2023-09-24 17:40:02 UTC
Date/Publication: 2023-10-06 01:40:02 UTC
30 changes: 15 additions & 15 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
a78c33f88f25528851586f911bf045c8 *DESCRIPTION
3ab48b1e0f826f081f15ca2fb94e45cf *DESCRIPTION
a95ab0a827028110692a7dae2aa99101 *NAMESPACE
c0c72f922790054e32b01a5121f05756 *NEWS.md
c745579e8c67d0726cc8aee47ed10aa2 *NEWS.md
44d2cae832bf363be8ac99818104adc8 *R/auto_melt.R
3438b2c41e9c5a049d9b31e0714995d3 *R/auto_merge.R
bc81ea22ea5149886b6d5ff67234e605 *R/auto_merge.R
b263764e99818915c3af9f626a0bc694 *R/check_wide_format.R
d19385c957b0aebccd98e06d0a002099 *R/country_info.R
e7af7478b451016330354b213dab11e5 *R/country_name.R
03391868c58bbb920a5ce7552512b907 *R/country_info.R
f8c76dfbec9eced28e735d54ec886d71 *R/country_name.R
9d42485df3c3364640c7884eae4f95e5 *R/data_long.R
988b9c53e5c74cbcc7e34f576383c778 *R/data_wide.R
d68c0805e97fddf25e5845f6e0acfa2f *R/data_world.R
Expand All @@ -14,34 +14,34 @@ a48310b1e0ab29b8d167c09cd2c0f3e6 *R/find_countrycol.R
341fdd3989356adaafec9f49047ba9a4 *R/find_timecol.R
b2350fbae252c2e2b469fefe2a211e0a *R/has.invalid.multibyte.string.R
71e679eb2e99de151bcc99379a221851 *R/is.yearcol.R
e9377c4e7fec1342928925b45985c09d *R/is_country.R
05ae14abc20966280c0b73a7d14760bf *R/is_country.R
7462073eb90f69ca8c86a8574c3a58b6 *R/is_date.R
9b1fa35aec228a0511cd32ddf57674c0 *R/is_keycol.R
ef073b1907f50c76632b62e95c098bf3 *R/list_fields.R
b7c879f029d3c13a69879f5b16aa3626 *R/map_palettes_and_themes.R
903deb275bbbe443a65c0f6db06b8904 *R/match_table.R
2f85ce9471994478ff99642ee385f953 *R/mode.R
04f81cb55a4178e458c809adcf0686bf *R/map_palettes_and_themes.R
3f164ca18157465f497241944a8cff50 *R/match_table.R
e64ed8f5b3bf0eb7cdbd99cfe1f78538 *R/mode.R
801ce683187752219c523bce5ddbeb8a *R/parse.by.order.R
5a37546d74ead984da1179870df4876c *R/quick_map.R
1528a14e4885c488e4d5b928456c6944 *R/quick_map.R
97cb01db7d9786585a3ae48dbcebed68 *R/sysdata.rda
8aa6f00a0f289c0cb7a690d701708e6f *R/which_min-max-mode.R
19cf5809388a8ad0a028a39979e101a7 *README.md
3d861abf386966d73588fe55d7513e99 *R/which_min-max-mode.R
c46a24fdd0076f024aa44c36e2cd3794 *README.md
e2f048aeb1ff5b9f5ad7f33c914ad454 *build/vignette.rds
1e375b313bfda9eb653a05ffd9924cda *data/country_reference_list.rda
0cf365f67f04b8a449ae14008f43f268 *data/country_reference_list_long.rda
1f0663373d69793da7b98914a2a9ed16 *data/world.rda
71b16632b064c42439c8c869a1f639e3 *inst/doc/auto_merge.R
c5cfe6ac0e8888634d23da4f1dfec0be *inst/doc/auto_merge.Rmd
8264ab2566b2e8a0fd09a01914e34aca *inst/doc/auto_merge.html
783036f9489c43717193fba3227154e0 *inst/doc/auto_merge.html
dc91c637da076712507555f7d80a32c3 *inst/doc/data_structure.R
d876d0ec1d539156ca867838b51583ed *inst/doc/data_structure.Rmd
6247c039b19eb7f8dd1ae76f35599d38 *inst/doc/data_structure.html
33eae072bf805fe679157f51928bb165 *inst/doc/data_structure.html
ee51f9ba307b28bb2acaf315a81a06cb *inst/doc/dealing_with_names.R
0088a25ad588b8d95628009bd1e63555 *inst/doc/dealing_with_names.Rmd
820e1a3ba367d48dad727f95169b0afe *inst/doc/dealing_with_names.html
7356195d829dfe56994b6b58b3e46d92 *inst/doc/quick_map.R
19e68c3cc34e35e63a7d46c4ff215d6e *inst/doc/quick_map.Rmd
a00b91710316338104b728716bfd6ea9 *inst/doc/quick_map.html
b12afb087c777cd96574ad76d6318a70 *inst/doc/quick_map.html
0c1d510e5c29173f65fd62d049283568 *man/Mode.Rd
a733f14d4c729e69d74ce50312799e02 *man/auto_melt.Rd
b35bafe1f838b98969a0be6c59e3541e *man/auto_merge.Rd
Expand Down
95 changes: 50 additions & 45 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,50 @@
# countries 1.0.4
* Fixed bug in *auto_merge* that was preventing column names to be passed in *by* order for regular expressions.

# countries 1.0.3
* Fixed hyperlinks in for resubmission
* Eliminated references to unexported objects in documentation
* Package accepted on CRAN!!

# countries 1.0
* First CRAN submission

# countries 0.3

* Added function *country_info()* to download information about countries (e.g. capital city, currency, neighbouring countries, etc.)
* Added function *list_fields()* returning a list of accepted fields for *country_info()*
* Added function *auto_merge()* to quickly join multiple dataset and automatically deal with country names and time columns
* Added function *auto_melt()* to automatically pivot tables containing country names and years in their headers
* Added function *quick_map()* to easily plot coloured country maps
* Added function *palettes_countries()* providing access to the package's colour themes
* Added vignette on plotting chloropleth maps with *quick_map* and merging country data with *auto_merge()*
* Bug fixes

# countries 0.2

* Added function *is_country()* to test whether a string is a country name or related to list of countries names
* Added function *is_date()* to test whether values are dates
* Added function *is_keycol()* to test whether a set of columns could be the keys of a table
* Added function *find_countrycol()* to automate search of columns containing country names in data frames
* Added function *find_timecol()* to automate search of date and/or year columns in data frames
* Added function *find_keycol()* to automate search of table keys in data frames
* Added functions *which_min()*, *which_max()* and *which_mode()* returning all the positions of vector's minimum, maximum and mode values.
* Speed improvements for the functions *country_name()* and *match_table()*
* Bug fixes
* Added vignette on data structure



# countries 0.1

* Function *country_name()* for converting and translating country names based on a fuzzy matching approach
* Function *match_table()* to easily construct conversion tables with the help of fuzzy matching algorithm
* Function *Mode()* returns the statistical mode of a vectors (most frequent observation)
* Dataset *country_reference_list* containing a country names in different languages and naming conventions
* Added vignettes and documentation
* Created website for the package
# countries 1.0.5

# countries 1.0.4
* Patch to address change in behaviour of function *is.atomic*

# countries 1.0.4
* Fixed bug in *auto_merge* that was preventing column names to be passed in *by* order for regular expressions.

# countries 1.0.3
* Fixed hyperlinks in for resubmission
* Eliminated references to unexported objects in documentation
* Package accepted on CRAN!!

# countries 1.0
* First CRAN submission

# countries 0.3

* Added function *country_info()* to download information about countries (e.g. capital city, currency, neighbouring countries, etc.)
* Added function *list_fields()* returning a list of accepted fields for *country_info()*
* Added function *auto_merge()* to quickly join multiple dataset and automatically deal with country names and time columns
* Added function *auto_melt()* to automatically pivot tables containing country names and years in their headers
* Added function *quick_map()* to easily plot coloured country maps
* Added function *palettes_countries()* providing access to the package's colour themes
* Added vignette on plotting chloropleth maps with *quick_map* and merging country data with *auto_merge()*
* Bug fixes

# countries 0.2

* Added function *is_country()* to test whether a string is a country name or related to list of countries names
* Added function *is_date()* to test whether values are dates
* Added function *is_keycol()* to test whether a set of columns could be the keys of a table
* Added function *find_countrycol()* to automate search of columns containing country names in data frames
* Added function *find_timecol()* to automate search of date and/or year columns in data frames
* Added function *find_keycol()* to automate search of table keys in data frames
* Added functions *which_min()*, *which_max()* and *which_mode()* returning all the positions of vector's minimum, maximum and mode values.
* Speed improvements for the functions *country_name()* and *match_table()*
* Bug fixes
* Added vignette on data structure



# countries 0.1

* Function *country_name()* for converting and translating country names based on a fuzzy matching approach
* Function *match_table()* to easily construct conversion tables with the help of fuzzy matching algorithm
* Function *Mode()* returns the statistical mode of a vectors (most frequent observation)
* Dataset *country_reference_list* containing a country names in different languages and naming conventions
* Added vignettes and documentation
* Created website for the package
4 changes: 2 additions & 2 deletions R/auto_merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ auto_merge <- function(... , by=NULL, country_to = "ISO3", inner_join = FALSE, m

if (length(data)<2) stop("At least two tables need to be provided for merging")
if (any(sapply(data, ncol)<2) | any(sapply(data, nrow)==0)) stop("Unable to proceed: input data tables need to have at least two columns and one row")
if (!is.atomic(by)&!is.list(by)) stop("Function argument - by - is invalid. It needs to be either a vector of regular expressions, or a list of column names. Refer to the documentation for more information.")
if (!(is.atomic(by)||is.null(by))& !is.list(by)) stop("Function argument - by - is invalid. It needs to be either a vector of regular expressions, or a list of column names. Refer to the documentation for more information.")
if (is.list(by)){
if (!all(sapply(by,is.atomic))) stop("Function argument - by - is invalid. List input needs to contain vectors of column names to merge")
if (!all(sapply(by, is.atomic))) stop("Function argument - by - is invalid. List input needs to contain vectors of column names to merge")
if (any(sapply(by,function(x){all(is.na(x))}))) stop("Function argument - by - is invalid. One of the name vectors contains all NAs")
if (length(unique(sapply(by, length))) != 1) stop("Function argument - by - is invalid. Length of name vectors differ from the number of provided tables.")
}
Expand Down
13 changes: 9 additions & 4 deletions R/country_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ country_info <- function(countries = NULL, fields = NULL, fuzzy_match = TRUE, ma
# check input format
if (!is.logical(fuzzy_match) | length(fuzzy_match)!=1) stop("Function argument - fuzzy_match - needs to be a single logical statement (TRUE/FALSE)")
if (!is.logical(match_info) | length(match_info)!=1) stop("Function argument - match_info - needs to be a single logical statement (TRUE/FALSE)")
if (!is.atomic(countries)) stop("Function argument - countries - needs to be a vector of country names")
if (!is.atomic(fields)) stop("Function argument - fields - needs to be a character vector")
if (all(is.na(countries)) & !is.null(countries)) stop("Only NAs in function argument - countries -")
if (all(is.na(fields)) & !is.null(fields)) stop("Only NAs in function argument - fields -")
if (!(is.atomic(countries) || is.null(countries))) stop("Function argument - countries - needs to be a vector of country names")
if (length(countries)>0){
if (all(is.na(countries))) stop("All elements in input - countries - are NAs")
}
if (!is.null(fields)){
if (!is.atomic(fields)) stop("Function argument - fields - needs to be a character vector")
if (all(is.na(fields))) stop("Only NAs in function argument - fields -")
}


# convert inputs to character
countries <- as.character(countries)
Expand Down
2 changes: 1 addition & 1 deletion R/country_name.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ country_name <- function(x,

if (all(is.na(x))){

message("All values in argument - x - are NA")
message("All values in argument - x - are NA or NULL")
return(rep(NA, length(x)))

} else{
Expand Down
10 changes: 9 additions & 1 deletion R/is_country.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ is_country <- function(x, check_for=NULL, fuzzy_match=FALSE){
#check inputs
if (!is.logical(fuzzy_match) | length(fuzzy_match)!=1) stop("Function argument - fuzzy_match - needs to be a logical statement (TRUE/FALSE)")
if (all(is.na(check_for))&!is.null(check_for)) stop("Function argument - check_for - needs to be a vector of country names.")
if (!is.atomic(x)) stop("Function argument - x - needs to be a character vector")
if (is.null(x)){
return(logical(0))
} else {
if (!is.atomic(x)) {
stop("Function argument - x - needs to be a character vector")
} else {
if (all(is.na(x))) return(rep(NA, length(x)))
}
}
x <- as.character(x)

#clean inputs and give error if a country is not recognised exactly
Expand Down
1 change: 1 addition & 0 deletions R/map_palettes_and_themes.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ palettes_countries <- function(n, theme = 1, reverse = FALSE){

# perform checks on inputs
if (!is.numeric(n)|length(n)!=1|is.na(n)) stop("invalid input for - n - it needs to be a number")
if (is.null(theme)) stop("NULL is an invalid input for - theme - it needs to be one of the themes' names or an integer value")
if (!is.atomic(theme)|is.logical(theme)|length(theme)>1) stop("invalid input for - theme - it needs to be a valid theme name or integer")
if (!is.logical(reverse) | length(reverse)!=1) stop("Function argument - reverse - needs to be a logical statement (TRUE/FALSE)")
if (is.na(reverse)|is.null(reverse)) stop("The argument - reverse - cannot be NA or NULL. It needs to be a logical value")
Expand Down
4 changes: 2 additions & 2 deletions R/match_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ match_table <- function(x,

#CHECK VALIDITY OF FUNCTION ARGUMENTS :-------------------
if (is.factor(x)) x <- as.character(x)
if (is.null(x)) stop("NULL provided in argument - x")
if (!is.atomic(x)) stop("The function argument - x - needs to be a vector")
if (all(is.na(x))) stop("All values in argument - x - are NA")
if (is.null(x)) stop("No value provided in argument - x")
if (all(is.na(x))) return(rep(NA_character_, length(x)))
if (!is.logical(fuzzy_match) | length(fuzzy_match)!=1) stop("Function argument - fuzzy_match - needs to be a logical statement (TRUE/FALSE)")
if (!is.logical(verbose) | length(verbose)!=1) stop("Function argument - verbose - needs to be a logical statement (TRUE/FALSE)")
if (!is.logical(matching_info) & length(matching_info)!=1) stop("Function argument - matching_info - needs to be a logical statement (TRUE/FALSE)")
Expand Down
1 change: 1 addition & 0 deletions R/mode.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Mode <- function(x,

# CHECK INPUTS ----

if (is.null(x)){return(NULL)}
if (!is.atomic(x)){stop("Argument - x - needs to be a vector")}
if (!is.logical(na.rm)|any(is.na(na.rm))|is.null(na.rm)){stop("Argument - na.rm - needs to be a logical value: TRUE / FALSE")}
if (length(na.rm)>1){stop("Argument - na.rm - needs to be of length 1")}
Expand Down
6 changes: 5 additions & 1 deletion R/quick_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,16 @@ quick_map <- function(data, plot_col,
if (!is.logical(verbose) | length(verbose)!=1) stop("Function argument - verbose - needs to be a logical statement (TRUE/FALSE)")
if (!is.logical(reverse_palette) | length(reverse_palette)!=1) stop("Function argument - reverse_palette - needs to be a logical statement (TRUE/FALSE)")
if (is.na(reverse_palette)|is.null(reverse_palette)) stop("The argument - reverse_palette - cannot be NA or NULL. It needs to be a logical value")
if (is.null(zoom)) stop("NULL is an invalid input for - zoom - needs to be a vector of lat/long values or a name of one of the predefined regions. Use - 'Default' - instead?")
if (!is.atomic(zoom)) stop("invalid input for - zoom - needs to be a vector of lat/long values or a name of one of the predefined regions")
if (!methods::is(width_plot, "numeric") | length(width_plot) != 1 | any(is.na(width_plot))) stop("invalid input for - width_plot - needs to be a positive numeric value")
if (width_plot <= 0) stop("invalid input for - width_plot - needs to be a positive numeric value")
if (!is.null(save_to)){
if (!methods::is(save_to, "character") | length(save_to) > 1 | any(is.na(save_to))) stop("invalid input for - save_to - needs to be a string containing the path to where you wish to save the map")
}
if (is.na(col_border)|!is.atomic(col_border)| !methods::is(col_border, "character") |is.logical(col_border)|length(col_border)>1) stop("invalid input for - col_border - it needs to be a single colour name")
if (is.null(col_border)) stop("Input - col_na - cannot be NULL")
if (is.na(col_border)| !(is.atomic(col_border) || is.null(col_border)) | !methods::is(col_border, "character") |is.logical(col_border)) stop("invalid input for - col_border - it needs to be a single colour name")
if (is.null(col_na)) stop("Input - col_na - cannot be NULL")
if (is.na(col_na)|!is.atomic(col_na)| !methods::is(col_na, "character")|is.logical(col_na)|length(col_na)>1) stop("invalid input for - col_na - it needs to be a single colour name")
if (!is.null(col_breaks)){
if (!is.atomic(col_breaks)| !methods::is(col_breaks,"numeric")) stop("invalid input for - col_breaks - please provide numberic breaks for the colour scale")
Expand All @@ -82,6 +85,7 @@ quick_map <- function(data, plot_col,
# predefined themes
theme_numbers <- 1:11
theme_names <- c("Default", "Greyscale", "Candy", "RedBlue", "Dark", "Reds", "Blues", "Greens", "Viridis", "Cividis", "Distinct")
if (is.null(theme)) stop("Input - theme - cannot be NULL. Use 1 instead?")
if (!is.atomic(theme)|is.logical(theme)|length(theme)>1) stop("invalid input for - theme - it needs to be a valid theme name or integer")
if (!(theme %in% c(0, theme_numbers) | theme %in% c("NoTheme", theme_names))) stop("invalid input for - theme - it needs to be a valid theme name or integer")

Expand Down
2 changes: 2 additions & 0 deletions R/which_min-max-mode.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
which_min <- function(x, first_only=FALSE){

#CHECK INPUTS ----
if (is.null(x)) return(NULL)
if (!is.atomic(x)|is.character(x)|is.factor(x)){stop("Argument - x - needs to be a numeric or logical vector")}
if (!is.logical(first_only)|any(is.na(first_only))|is.null(first_only)){stop("Argument - first_only - needs to be a logical value: TRUE / FALSE")}
if (length(first_only)>1){stop("Argument - first_only - needs to be of length 1")}
Expand All @@ -35,6 +36,7 @@ which_min <- function(x, first_only=FALSE){
which_max <- function(x, first_only=FALSE){

#CHECK INPUTS ----
if (is.null(x)) return(NULL)
if (!is.atomic(x)|is.character(x)|is.factor(x)){stop("Argument - x - needs to be a numeric or logical vector")}
if (!is.logical(first_only)|any(is.na(first_only))|is.null(first_only)){stop("Argument - first_only - needs to be a logical value: TRUE / FALSE")}
if (length(first_only)>1){stop("Argument - first_only - needs to be of length 1")}
Expand Down

0 comments on commit d65a909

Please sign in to comment.