Skip to content

Commit 1e4b43b

Browse files
committed
Merge branch 'WIP]-issue-dapperstats#12'
2 parents b3a41dd + bb9af8e commit 1e4b43b

File tree

6 files changed

+113
-65
lines changed

6 files changed

+113
-65
lines changed

Diff for: DESCRIPTION

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ Suggests:
1414
covr,
1515
pkgdown,
1616
testthat
17+
Imports: countrycode
1718
RoxygenNote: 6.1.1
1819
Encoding: UTF-8

Diff for: NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export(gendr)
55
export(gendr_warning)
66
export(get_locale)
77
export(ifnull)
8+
importFrom(countrycode,countrycode)
89
importFrom(stats,setNames)

Diff for: R/gendr.R

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
#' @title Do not assign gender to someone
22
#'
3-
#' @description Recognizing that gender is an individual, person
4-
#' characteristic, it is impossible to accurately assign gender to another.
5-
#' Further, assigning genders to those who have been incorrectly assigned
6-
#' genders is a retraumatizing, violent act. Finally, gender is a
7-
#' spatiotemporally evolving concept, and therefore by definition, the
8-
#' gender of an individual in a given space and time may not be accurately
9-
#' predicted by the genders of other individuals in other spaces and/or
10-
#' times. A particularly prescient example of this is the recent-historic
11-
#' Euro-centric notion of a gender binary, which is a false construct that
12-
#' has been nonetheless used to define genders on a massive scale. \cr \cr
13-
#' \code{gendr} acknowledges these shortcomings when asked to assign the
14-
#' gender of an individual. \cr \cr
15-
#' \code{gendr_warning} produces a warning if necessary (it's necessary).
3+
#' @description Recognizing that gender is an individual, person characteristic,
4+
#' it is impossible to accurately assign gender to another. Further, assigning
5+
#' genders to those who have been incorrectly assigned genders is a
6+
#' retraumatizing, violent act. Finally, gender is a spatiotemporally evolving
7+
#' concept, and therefore by definition, the gender of an individual in a
8+
#' given space and time may not be accurately predicted by the genders of
9+
#' other individuals in other spaces and/or times. A particularly prescient
10+
#' example of this is the recent-historic Euro-centric notion of a gender
11+
#' binary, which is a false construct that has been nonetheless used to define
12+
#' genders on a massive scale. \cr \cr \code{gendr} acknowledges these
13+
#' shortcomings when asked to assign the gender of an individual. \cr \cr
14+
#' \code{gendr_warning} produces a warning if necessary (it's necessary).
15+
#'
16+
#' @details \code{get_locale()} now expands ISO names of language and location
17+
#' into full automatically for MacOS. Set argument \code{locale_asis}
18+
#' \strong{FALSE} for \code{get_locale} to see ISO names as they are.
1619
#'
1720
#' @param names \code{character} vector of first names. All options available.
1821
#'
19-
#' @param locations \code{character} vector of locations. All options
20-
#' available.
22+
#' @param locations \code{character} vector of locations. All options available.
2123
#'
22-
#' @param languages \code{character} vector of languages. All options
23-
#' available.
24+
#' @param languages \code{character} vector of languages. All options available.
2425
#'
25-
#' @param years \code{integer}-conformable vector of years. All options
26+
#' @param years \code{integer}-conformable vector of years. All options
2627
#' available.
2728
#'
2829
#' @param methods \code{character} vector of methods. All options available.
2930
#'
30-
#' @return
31-
#' \code{gendr}: \code{data.frame} of genders for inputs. \cr
32-
#' \code{gendr_warning}: \code{NULL}, warning is produced.
31+
#' @return \code{gendr}: \code{data.frame} of genders for inputs. \cr
32+
#' \code{gendr_warning}: \code{NULL}, warning is produced.
3333
#'
3434
#' @examples
3535
#' \donttest{
3636
#' gendr("max", "usa", "english", 1990) # produces warning
37-
#' gendr() # produces warning
37+
#' gendr() # produces warning
3838
#' gendr_warning() # produces warning
3939
#' }
4040
#'
4141
#' @export
42-
#'
42+
#'
4343
gendr <- function(names = NULL, locations = NULL, languages = NULL,
4444
years = NULL, methods = "standard"){
4545

Diff for: R/utilities.R

+55-15
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,27 @@ check_type <- function(x, type){
6464

6565
#' @title Get the language and location of a system locale
6666
#'
67-
#' @description OS-flexible approach to determining the system locale with
68-
#' respect to language and location.
69-
#'
70-
#' @param category \code{character} string of the locale environmental
71-
#' variable to use, passed directly to \code{\link[base]{Sys.getlocale}}.
67+
#' @description OS-flexible approach to determining the system locale with
68+
#' respect to language and location.
69+
#'
70+
#' @param category \code{character} string of the locale environmental variable
71+
#' to use, passed directly to \code{\link[base]{Sys.getlocale}}.
72+
#'
73+
#' @param locale_asis \code{boolean} for returning \emph{language} and
74+
#' \emph{location} from \link[base]{Sys.getlocale} as it is. Defult to
75+
#' FALSE.
76+
#'
77+
#' @return \code{character} vector with elements \code{"language"} and
78+
#' \code{"location"}.
79+
#'
80+
#' @importFrom countrycode countrycode
7281
#'
73-
#' @return \code{character} vector with elements \code{"language"} and
74-
#' \code{"location"}.
75-
#'
7682
#' @examples
7783
#' get_locale()
7884
#'
79-
#' @export
80-
#'
81-
get_locale <- function(category = "LC_TIME"){
85+
#' @export
86+
#'
87+
get_locale <- function(category = "LC_TIME", locale_asis = FALSE){
8288
ismac <- Sys.info()["sysname"] == "Darwin"
8389
issolaris <- Sys.info()["sysname"] == "SunOS"
8490
splitchar <- ifelse(ismac | issolaris, "/", ";")
@@ -88,8 +94,42 @@ get_locale <- function(category = "LC_TIME"){
8894
locale <- strsplit(locale, "_")[[1]]
8995
locale <- setNames(locale, c("language", "location"))
9096
locale[["location"]] <- sub("\\..*", "", locale[["location"]])
91-
locale
92-
}
93-
94-
97+
98+
language_codes <- c('af', 'sq', 'ar', 'hy', 'az', 'eu', 'be', 'bn', 'bs',
99+
'bg', 'ca', 'ceb', 'zh-CN', 'zh-TW', 'hr', 'cs', 'da',
100+
'nl', 'en', 'eo', 'et', 'tl', 'fi', 'fr', 'gl', 'ka',
101+
'de', 'el', 'gu', 'ht', 'ha', 'iw', 'hi', 'hmn', 'hu',
102+
'is', 'ig', 'id', 'ga', 'it', 'ja', 'jw', 'kn', 'km',
103+
'ko', 'lo', 'la', 'lv', 'lt', 'mk', 'ms', 'mt', 'mi',
104+
'mr', 'mn', 'ne', 'no', 'fa', 'pl', 'pt', 'pa', 'ro',
105+
'ru', 'sr', 'sk', 'sl', 'so', 'es', 'sw', 'sv', 'ta',
106+
'te', 'th', 'tr', 'uk', 'ur', 'vi', 'cy', 'yi', 'yo',
107+
'zu')
108+
language_names <- c('Afrikaans', 'Albanian', 'Arabic', 'Armenian',
109+
'Azerbaijani', 'Basque', 'Belarusian', 'Bengali',
110+
'Bosnian', 'Bulgarian', 'Catalan', 'Cebuano',
111+
'Chinese_Simplified', 'Chinese_Traditional',
112+
'Croatian', 'Czech', 'Danish', 'Dutch', 'English',
113+
'Esperanto', 'Estonian', 'Filipino', 'Finnish',
114+
'French', 'Galician', 'Georgian', 'German', 'Greek',
115+
'Gujarati', 'Haitian_Creole', 'Hausa', 'Hebrew',
116+
'Hindi', 'Hmong', 'Hungarian', 'Icelandic', 'Igbo',
117+
'Indonesian', 'Irish', 'Italian', 'Japanese',
118+
'Javanese', 'Kannada', 'Khmer', 'Korean', 'Lao',
119+
'Latin', 'Latvian', 'Lithuanian', 'Macedonian',
120+
'Malay', 'Maltese', 'Maori', 'Marathi', 'Mongolian',
121+
'Nepali', 'Norwegian', 'Persian', 'Polish',
122+
'Portuguese', 'Punjabi', 'Romanian', 'Russian',
123+
'Serbian', 'Slovak', 'Slovenian', 'Somali', 'Spanish',
124+
'Swahili', 'Swedish', 'Tamil', 'Telugu', 'Thai',
125+
'Turkish', 'Ukrainian', 'Urdu', 'Vietnamese', 'Welsh',
126+
'Yiddish', 'Yoruba', 'Zulu')
127+
names(language_codes) <- language_names
95128

129+
if(!locale_asis && (ismac | issolaris)) {
130+
locale["language"] <- names(which(language_codes == locale["language"]))
131+
locale["location"] <- countrycode(locale["location"],
132+
"eurostat", "un.name.en")
133+
}
134+
return(locale)
135+
}

Diff for: man/gendr.Rd

+22-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: man/get_locale.Rd

+11-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)