Skip to content

Commit 3b93c21

Browse files
committed
add rename_languages argument; fix some documentation
1 parent c1a2f57 commit 3b93c21

6 files changed

Lines changed: 136 additions & 10 deletions

File tree

R/ec_tile_map.R

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#' @param annotate_feature Logical variable that specifies, whether to add feature values on the tile. This especially make sense in case of numeric features. Default value is \code{FALSE}.
88
#' @param abbreviation Logical variable that specifies, whether use abbreviations for languages specified in the package. Default value is \code{TRUE}.
99
#' @param hide_languages Character variable that specifies, which languages should be removed from the template.
10+
#' @param rename_languages This variable maps old language names to their corresponding new names. It can be represented as either:
11+
#' \itemize{
12+
#' \item{A named vector, where names are the old language names and values are the corresponding new language names.}
13+
#' \item{A data frame with two columns: \code{language} (the old language names) and \code{new_language_name} (the corresponding new language names).}}
1014
#'
1115
#' @returns a `ggplot2` object
1216
#' @export
@@ -43,7 +47,8 @@ ec_tile_map <- function(data = NULL,
4347
title_position = "left",
4448
annotate_feature = FALSE,
4549
abbreviation = TRUE,
46-
hide_languages = NULL) {
50+
hide_languages = NULL,
51+
rename_languages = NULL) {
4752

4853
# arguments check ---------------------------------------------------------
4954

@@ -67,9 +72,33 @@ ec_tile_map <- function(data = NULL,
6772
is.character(hide_languages) | is.null(hide_languages),
6873
"The argument 'hide_languages' should be a character vector with languages, see 'ec_languages$language' for the possible values" =
6974
is.null(hide_languages) |
70-
hide_languages %in% RCaucTile::ec_languages$language)
75+
hide_languages %in% RCaucTile::ec_languages$language,
76+
"The argument 'rename_languages' should be either a named character vector with languages as a name or dataframe with columns 'language' and 'new_language_name', see 'ec_languages$language' for the possible values" =
77+
is.null(rename_languages) | "character" %in% class(rename_languages) | "data.frame" %in% class(rename_languages))
7178

72-
# redefine title_position -------------------------------------------------
79+
if("data.frame" %in% class(rename_languages)){
80+
stopifnot(
81+
"The argument 'rename_languages' should be either a named character vector with languages as a name or dataframe with columns 'language' and 'new_language_name', see 'ec_languages$language' for the possible values" =
82+
"language" %in% colnames(rename_languages),
83+
"The argument 'rename_languages' should be either a named character vector with languages as a name or dataframe with columns 'language' and 'new_language_name', see 'ec_languages$language' for the possible values" =
84+
"new_language_name" %in% colnames(rename_languages),
85+
"The 'language' column in 'rename_languages' contains unexpected values, see 'ec_languages$language' for the possible values" =
86+
rename_languages$language %in% RCaucTile::ec_languages$language)
87+
} else if("character" %in% class(rename_languages)){
88+
stopifnot(
89+
"The names in 'rename_languages' contain unexpected values, see 'ec_languages$language' for the possible values" =
90+
names(rename_languages) %in% RCaucTile::ec_languages$language)
91+
}
92+
93+
# restructure rename_languages --------------------------------------------
94+
95+
if("character" %in% class(rename_languages)){
96+
rename_languages <- as.data.frame(rename_languages)
97+
colnames(rename_languages) <- "new_language_name"
98+
rename_languages$language <- rownames(rename_languages)
99+
}
100+
101+
# redefine title_position -------------------------------------------------
73102

74103
if(title_position == "left") {
75104
title_position <- 0
@@ -99,15 +128,30 @@ ec_tile_map <- function(data = NULL,
99128
"The argument 'feature_column' should be a character vector with one value" =
100129
length(feature_column) == 1)
101130

102-
# merge EC dataset with data provided by a user ---------------------------
131+
# merge EC dataset with data provided by a user ---------------------------
103132

104133
for_plot <- merge(RCaucTile::ec_languages, data, all.x = TRUE)
105134

135+
136+
# rename languages --------------------------------------------------------
137+
138+
if(!is.null(rename_languages)){
139+
for_plot <- merge(for_plot, rename_languages, all.x = TRUE)
140+
for_plot$language <- ifelse(is.na(for_plot$new_language_name),
141+
for_plot$language,
142+
for_plot$new_language_name)
143+
for_plot$abbreviation <- ifelse(is.na(for_plot$new_language_name),
144+
for_plot$abbreviation,
145+
for_plot$new_language_name)
146+
}
147+
148+
# hide languages ----------------------------------------------------------
149+
106150
if(!is.null(hide_languages)){
107151
for_plot <- for_plot[!(for_plot$language %in% hide_languages), ]
108152
}
109153

110-
# create a column with the name feature if there is no one ----------------
154+
# create a column with the name feature if there is no one ----------------
111155

112156
names(for_plot)[names(for_plot) == feature_column] <- "feature"
113157

docs/index.html

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,12 @@ <h2 data-number="5" class="anchored" data-anchor-id="changing-values-order"><spa
400400
<section id="changing-the-language-template" class="level2" data-number="6">
401401
<h2 data-number="6" class="anchored" data-anchor-id="changing-the-language-template"><span class="header-section-number">6</span> Changing the language template</h2>
402402
<p>The East Caucasian language family exhibits significant dialectal differentiation. A unified genealogical classification of all idioms spoken in Daghestan does not exist. The default language inventory in <code>RCaucTile</code> is based on the genealogical classification from the Typological Atlas of the Languages of Daghestan (see <a href="https://lingconlab.ru/tald/languages.html">the languages page</a>). Therefore, it is highly probable that some researchers may wish to modify the default inventory by removing or altering the names of existing units.</p>
403-
<p>To remove specific languages from the template, list the desired languages in the <code>remove_languages</code> argument.</p>
403+
<p>To remove specific languages from the template, list the desired languages in the <code>hide_languages</code> argument.</p>
404404
<div class="cell">
405405
<div class="sourceCode cell-code" id="cb25"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ec_tile_map</span>(ec_languages,</span>
406406
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a> <span class="at">feature_column =</span> <span class="st">"morning_greetings"</span>,</span>
407407
<span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a> <span class="at">title =</span> <span class="st">"Morning greetings (Naccarato, Verhees 2021)"</span>,</span>
408-
<span id="cb25-4"><a href="#cb25-4" aria-hidden="true" tabindex="-1"></a> <span class="at">remove_languages =</span> <span class="fu">c</span>(<span class="st">"Gigatli"</span>, <span class="st">"Shari"</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
408+
<span id="cb25-4"><a href="#cb25-4" aria-hidden="true" tabindex="-1"></a> <span class="at">hide_languages =</span> <span class="fu">c</span>(<span class="st">"Gigatli"</span>, <span class="st">"Shari"</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
409409
<div class="cell-output-display">
410410
<div>
411411
<figure class="figure">
@@ -414,7 +414,52 @@ <h2 data-number="6" class="anchored" data-anchor-id="changing-the-language-templ
414414
</div>
415415
</div>
416416
</div>
417-
<p>In order to change the names of existing languages in the template, you need …</p>
417+
<p>In order to change the names of existing languages in the template, you need to provide the <code>rename_languages</code> argument with an object that maps old language names to their corresponding new names. This can be represented as either:</p>
418+
<ul>
419+
<li>A named vector, where the names are the old language names and the values are the corresponding new language names.</li>
420+
</ul>
421+
<div class="cell">
422+
<div class="sourceCode cell-code" id="cb26"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a>new_language_names <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"Upper Andi"</span> <span class="ot">=</span> <span class="st">"Andi"</span>,</span>
423+
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a> <span class="st">"Northern Akhvakh"</span> <span class="ot">=</span> <span class="st">"Akhvakh"</span>)</span>
424+
<span id="cb26-3"><a href="#cb26-3" aria-hidden="true" tabindex="-1"></a></span>
425+
<span id="cb26-4"><a href="#cb26-4" aria-hidden="true" tabindex="-1"></a><span class="fu">ec_tile_map</span>(ec_languages,</span>
426+
<span id="cb26-5"><a href="#cb26-5" aria-hidden="true" tabindex="-1"></a> <span class="at">feature_column =</span> <span class="st">"morning_greetings"</span>,</span>
427+
<span id="cb26-6"><a href="#cb26-6" aria-hidden="true" tabindex="-1"></a> <span class="at">title =</span> <span class="st">"Morning greetings (Naccarato, Verhees 2021)"</span>,</span>
428+
<span id="cb26-7"><a href="#cb26-7" aria-hidden="true" tabindex="-1"></a> <span class="at">hide_languages =</span> <span class="fu">c</span>(<span class="st">"Lower Andi"</span>, <span class="st">"Southern Akhvakh"</span>),</span>
429+
<span id="cb26-8"><a href="#cb26-8" aria-hidden="true" tabindex="-1"></a> <span class="at">rename_languages =</span> new_language_names)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
430+
<div class="cell-output-display">
431+
<div>
432+
<figure class="figure">
433+
<p><img src="index_files/figure-html/unnamed-chunk-20-1.png" class="img-fluid figure-img" width="1152"></p>
434+
</figure>
435+
</div>
436+
</div>
437+
</div>
438+
<ul>
439+
<li>A data frame with two columns: <code>language</code> (the old language names) and <code>new_language_name</code> (the corresponding new language names).</li>
440+
</ul>
441+
<div class="cell">
442+
<div class="sourceCode cell-code" id="cb27"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a>new_language_names <span class="ot">&lt;-</span> <span class="fu">data.frame</span>(<span class="at">language =</span> <span class="fu">c</span>(<span class="st">"Upper Andi"</span>, <span class="st">"Northern Akhvakh"</span>),</span>
443+
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a> <span class="at">new_language_name =</span> <span class="fu">c</span>(<span class="st">"Andi"</span>, <span class="st">"Akhvakh"</span>))</span>
444+
<span id="cb27-3"><a href="#cb27-3" aria-hidden="true" tabindex="-1"></a></span>
445+
<span id="cb27-4"><a href="#cb27-4" aria-hidden="true" tabindex="-1"></a><span class="fu">ec_tile_map</span>(ec_languages,</span>
446+
<span id="cb27-5"><a href="#cb27-5" aria-hidden="true" tabindex="-1"></a> <span class="at">feature_column =</span> <span class="st">"morning_greetings"</span>,</span>
447+
<span id="cb27-6"><a href="#cb27-6" aria-hidden="true" tabindex="-1"></a> <span class="at">title =</span> <span class="st">"Morning greetings (Naccarato, Verhees 2021)"</span>,</span>
448+
<span id="cb27-7"><a href="#cb27-7" aria-hidden="true" tabindex="-1"></a> <span class="at">hide_languages =</span> <span class="fu">c</span>(<span class="st">"Lower Andi"</span>, <span class="st">"Southern Akhvakh"</span>),</span>
449+
<span id="cb27-8"><a href="#cb27-8" aria-hidden="true" tabindex="-1"></a> <span class="at">rename_languages =</span> new_language_names)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
450+
<div class="cell-output-display">
451+
<div>
452+
<figure class="figure">
453+
<p><img src="index_files/figure-html/unnamed-chunk-21-1.png" class="img-fluid figure-img" width="1152"></p>
454+
</figure>
455+
</div>
456+
</div>
457+
</div>
458+
<p>As shown in the example above, we merged:</p>
459+
<ul>
460+
<li>Upper and Lower Andi into the joint “Andi” variable;</li>
461+
<li>Southern and Northern Akhvakh into the joint “Akhvakh” variable.</li>
462+
</ul>
418463
</section>
419464

420465
</main>

docs/index.qmd

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,35 @@ ec_tile_map(ec_languages,
205205
hide_languages = c("Gigatli", "Shari"))
206206
```
207207

208-
In order to change the names of existing languages in the template, you need ...
208+
In order to change the names of existing languages in the template, you need to provide the `rename_languages` argument with an object that maps old language names to their corresponding new names. This can be represented as either:
209+
210+
- A named vector, where the names are the old language names and the values are the corresponding new language names.
211+
212+
```{r}
213+
new_language_names <- c("Upper Andi" = "Andi",
214+
"Northern Akhvakh" = "Akhvakh")
215+
216+
ec_tile_map(ec_languages,
217+
feature_column = "morning_greetings",
218+
title = "Morning greetings (Naccarato, Verhees 2021)",
219+
hide_languages = c("Lower Andi", "Southern Akhvakh"),
220+
rename_languages = new_language_names)
221+
```
222+
223+
- A data frame with two columns: `language` (the old language names) and `new_language_name` (the corresponding new language names).
224+
225+
```{r}
226+
new_language_names <- data.frame(language = c("Upper Andi", "Northern Akhvakh"),
227+
new_language_name = c("Andi", "Akhvakh"))
228+
229+
ec_tile_map(ec_languages,
230+
feature_column = "morning_greetings",
231+
title = "Morning greetings (Naccarato, Verhees 2021)",
232+
hide_languages = c("Lower Andi", "Southern Akhvakh"),
233+
rename_languages = new_language_names)
234+
```
235+
236+
As shown in the example above, we merged:
237+
238+
- Upper and Lower Andi into the joint "Andi" variable;
239+
- Southern and Northern Akhvakh into the joint "Akhvakh" variable.
149 KB
Loading
149 KB
Loading

man/ec_tile_map.Rd

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)