From 7c661b4284135e1f646e737d3a34720f5114dfc3 Mon Sep 17 00:00:00 2001 From: Ricardo Villalba Date: Sat, 23 Nov 2024 18:55:35 -0300 Subject: [PATCH 1/3] rebase from master --- vignettes/_translation_links.R | 25 +++++++++++++++++++ vignettes/datatable-benchmarking.Rmd | 6 ++--- vignettes/datatable-faq.Rmd | 8 +++--- vignettes/datatable-importing.Rmd | 6 ++--- vignettes/datatable-intro.Rmd | 8 +++--- vignettes/datatable-joins.Rmd | 4 +++ vignettes/datatable-keys-fast-subset.Rmd | 8 +++--- vignettes/datatable-programming.Rmd | 7 +++--- vignettes/datatable-reference-semantics.Rmd | 9 ++++--- vignettes/datatable-reshape.Rmd | 8 +++--- vignettes/datatable-sd-usage.Rmd | 8 +++--- ...le-secondary-indices-and-auto-indexing.Rmd | 8 +++--- 12 files changed, 67 insertions(+), 38 deletions(-) create mode 100644 vignettes/_translation_links.R diff --git a/vignettes/_translation_links.R b/vignettes/_translation_links.R new file mode 100644 index 000000000..324cf77c4 --- /dev/null +++ b/vignettes/_translation_links.R @@ -0,0 +1,25 @@ +# build a link list of alternative languages (may be character(0)) +.write.translation.links <- function(fmt) { + url = "https://rdatatable.gitlab.io/data.table/articles" + path = dirname(knitr::current_input(TRUE)) + if (basename(path) == "vignettes") { + lang = "en" + } else { + lang = basename(path) + path = dirname(path) + } + translation = dir(path, + recursive = TRUE, + pattern = glob2rx(knitr::current_input(FALSE)) + ) + transl_lang = ifelse(dirname(translation) == ".", "en", dirname(translation)) + block = if (length(which(transl_lang != lang))) { + sprintf( + fmt, paste(collapse = " | ", sprintf( + "[%s](%s)", + transl_lang[transl_lang != lang], + file.path(url, sub("(?i)\\.Rmd$", ".html", translation[transl_lang != lang])) + ))) + } else "" + knitr::asis_output(block) +} diff --git a/vignettes/datatable-benchmarking.Rmd b/vignettes/datatable-benchmarking.Rmd index 733b4914d..1a47d9530 100644 --- a/vignettes/datatable-benchmarking.Rmd +++ b/vignettes/datatable-benchmarking.Rmd @@ -25,9 +25,9 @@ h2 { } -Translations of this document are available in - -* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-benchmarking.html) +```{r echo=FALSE, file='_translation_links.R'} +``` +`r .write.translation.links("Translations of this document are available in: %s")` This document is meant to guide on measuring performance of `data.table`. Single place to document best practices and traps to avoid. diff --git a/vignettes/datatable-faq.Rmd b/vignettes/datatable-faq.Rmd index 4c6f4c633..e238082dd 100644 --- a/vignettes/datatable-faq.Rmd +++ b/vignettes/datatable-faq.Rmd @@ -26,10 +26,6 @@ h2 { } -Translations of this document are available in - -* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-faq.html) - ```{r, echo = FALSE, message = FALSE} library(data.table) knitr::opts_chunk$set( @@ -41,6 +37,10 @@ knitr::opts_chunk$set( .old.th = setDTthreads(1) ``` +```{r echo=FALSE, file='_translation_links.R'} +``` +`r .write.translation.links("Translations of this document are available in: %s")` + The first section, Beginner FAQs, is intended to be read in order, from start to finish. It's just written in a FAQ style to be digested more easily. It isn't really the most frequently asked questions. A better measure for that is looking on Stack Overflow. This FAQ is required reading and considered core documentation. Please do not ask questions on Stack Overflow or raise issues on GitHub until you have read it. We can all tell when you ask that you haven't read it. So if you do ask and haven't read it, don't use your real name. diff --git a/vignettes/datatable-importing.Rmd b/vignettes/datatable-importing.Rmd index 21e42b67c..5c030af09 100644 --- a/vignettes/datatable-importing.Rmd +++ b/vignettes/datatable-importing.Rmd @@ -15,9 +15,9 @@ h2 { } -Translations of this document are available in - -* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-importing.html) +```{r echo=FALSE, file='_translation_links.R'} +``` +`r .write.translation.links("Translations of this document are available in: %s")` This document is focused on using `data.table` as a dependency in other R packages. If you are interested in using `data.table` C code from a non-R application, or in calling its C functions directly, jump to the [last section](#non-r-api) of this vignette. diff --git a/vignettes/datatable-intro.Rmd b/vignettes/datatable-intro.Rmd index d32a25eb9..b5db5c9f4 100644 --- a/vignettes/datatable-intro.Rmd +++ b/vignettes/datatable-intro.Rmd @@ -9,10 +9,6 @@ vignette: > \usepackage[utf8]{inputenc} --- -Translations of this document are available in - -* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-intro.html) - ```{r, echo = FALSE, message = FALSE} require(data.table) knitr::opts_chunk$set( @@ -25,6 +21,10 @@ knitr::opts_chunk$set( .old.th = setDTthreads(1) ``` +```{r echo=FALSE, file='_translation_links.R'} +``` +`r .write.translation.links("Translations of this document are available in: %s")` + This vignette introduces the `data.table` syntax, its general form, how to *subset* rows, *select and compute* on columns, and perform aggregations *by group*. Familiarity with the `data.frame` data structure from base R is useful, but not essential to follow this vignette. *** diff --git a/vignettes/datatable-joins.Rmd b/vignettes/datatable-joins.Rmd index a35f78bb2..f296940bd 100644 --- a/vignettes/datatable-joins.Rmd +++ b/vignettes/datatable-joins.Rmd @@ -22,6 +22,10 @@ knitr::opts_chunk$set( ) ``` +```{r, echo=FALSE, file='_translation_links.R'} +``` +`r .write.translation.links("Translations of this document are available in: %s")` + In this vignette you will learn how to perform any join operation using resources available in the `data.table` syntax. It assumes familiarity with the `data.table` syntax. If that is not the case, please read the following vignettes: diff --git a/vignettes/datatable-keys-fast-subset.Rmd b/vignettes/datatable-keys-fast-subset.Rmd index 6f77c3de2..a44e6dc06 100644 --- a/vignettes/datatable-keys-fast-subset.Rmd +++ b/vignettes/datatable-keys-fast-subset.Rmd @@ -9,10 +9,6 @@ vignette: > \usepackage[utf8]{inputenc} --- -Translations of this document are available in - -* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-keys-fast-subset.html) - ```{r, echo = FALSE, message = FALSE} require(data.table) knitr::opts_chunk$set( @@ -24,6 +20,10 @@ knitr::opts_chunk$set( .old.th = setDTthreads(1) ``` +```{r echo=FALSE, file='_translation_links.R'} +``` +`r .write.translation.links("Translations of this document are available in: %s")` + This vignette is aimed at those who are already familiar with *data.table* syntax, its general form, how to subset rows in `i`, select and compute on columns, add/modify/delete columns *by reference* in `j` and group by using `by`. If you're not familiar with these concepts, please read the vignettes [`vignette("datatable-intro", package="data.table")`](datatable-intro.html) and [`vignette("datatable-reference-semantics", package="data.table")`](datatable-reference-semantics.html) first. *** diff --git a/vignettes/datatable-programming.Rmd b/vignettes/datatable-programming.Rmd index 93c6dc556..9264e181c 100644 --- a/vignettes/datatable-programming.Rmd +++ b/vignettes/datatable-programming.Rmd @@ -9,10 +9,6 @@ vignette: > \usepackage[utf8]{inputenc} --- -Translations of this document are available in - -* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-programming.html) - ```{r init, include = FALSE} require(data.table) knitr::opts_chunk$set( @@ -24,6 +20,9 @@ knitr::opts_chunk$set( ) ``` +```{r echo=FALSE, file='_translation_links.R'} +``` +`r .write.translation.links("Translations of this document are available in: %s")` ## Introduction diff --git a/vignettes/datatable-reference-semantics.Rmd b/vignettes/datatable-reference-semantics.Rmd index b6d895af1..750bb9b4e 100644 --- a/vignettes/datatable-reference-semantics.Rmd +++ b/vignettes/datatable-reference-semantics.Rmd @@ -9,10 +9,6 @@ vignette: > \usepackage[utf8]{inputenc} --- -Translations of this document are available in - -* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-reference-semantics.html) - ```{r, echo = FALSE, message = FALSE} require(data.table) knitr::opts_chunk$set( @@ -23,6 +19,11 @@ knitr::opts_chunk$set( collapse = TRUE) .old.th = setDTthreads(1) ``` + +```{r echo=FALSE, file='_translation_links.R'} +``` +`r .write.translation.links("Translations of this document are available in: %s")` + This vignette discusses *data.table*'s reference semantics which allows to *add/update/delete* columns of a *data.table by reference*, and also combine them with `i` and `by`. It is aimed at those who are already familiar with *data.table* syntax, its general form, how to subset rows in `i`, select and compute on columns, and perform aggregations by group. If you're not familiar with these concepts, please read the [`vignette("datatable-intro", package="data.table")`](datatable-intro.html) vignette first. *** diff --git a/vignettes/datatable-reshape.Rmd b/vignettes/datatable-reshape.Rmd index bf7b18e53..41691f386 100644 --- a/vignettes/datatable-reshape.Rmd +++ b/vignettes/datatable-reshape.Rmd @@ -9,10 +9,6 @@ vignette: > \usepackage[utf8]{inputenc} --- -Translations of this document are available in - -* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-reshape.html) - ```{r, echo = FALSE, message = FALSE} require(data.table) knitr::opts_chunk$set( @@ -24,6 +20,10 @@ knitr::opts_chunk$set( .old.th = setDTthreads(1) ``` +```{r echo=FALSE, file='_translation_links.R'} +``` +`r .write.translation.links("Translations of this document are available in: %s")` + This vignette discusses the default usage of reshaping functions `melt` (wide to long) and `dcast` (long to wide) for *data.tables* as well as the **new extended functionalities** of melting and casting on *multiple columns* available from `v1.9.6`. *** diff --git a/vignettes/datatable-sd-usage.Rmd b/vignettes/datatable-sd-usage.Rmd index 2f91f0bb1..069e692cb 100644 --- a/vignettes/datatable-sd-usage.Rmd +++ b/vignettes/datatable-sd-usage.Rmd @@ -21,10 +21,6 @@ vignette: > } -Translations of this document are available in - -* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-sd-usage.html) - ```{r, echo = FALSE, message = FALSE} require(data.table) knitr::opts_chunk$set( @@ -39,6 +35,10 @@ knitr::opts_chunk$set( .old.th = setDTthreads(1) ``` +```{r echo=FALSE, file='_translation_links.R'} +``` +`r .write.translation.links("Translations of this document are available in: %s")` + This vignette will explain the most common ways to use the `.SD` variable in your `data.table` analyses. It is an adaptation of [this answer](https://stackoverflow.com/a/47406952/3576984) given on StackOverflow. # What is `.SD`? diff --git a/vignettes/datatable-secondary-indices-and-auto-indexing.Rmd b/vignettes/datatable-secondary-indices-and-auto-indexing.Rmd index 7be917032..0de675247 100644 --- a/vignettes/datatable-secondary-indices-and-auto-indexing.Rmd +++ b/vignettes/datatable-secondary-indices-and-auto-indexing.Rmd @@ -9,10 +9,6 @@ vignette: > \usepackage[utf8]{inputenc} --- -Translations of this document are available in - -* [French](https://rdatatable.gitlab.io/data.table/articles/fr/datatable-secondary-indices-and-auto-indexing.html) - ```{r, echo = FALSE, message = FALSE} require(data.table) knitr::opts_chunk$set( @@ -24,6 +20,10 @@ knitr::opts_chunk$set( .old.th = setDTthreads(1) ``` +```{r echo=FALSE, file='_translation_links.R'} +``` +`r .write.translation.links("Translations of this document are available in: %s")` + This vignette assumes that the reader is familiar with data.table's `[i, j, by]` syntax, and how to perform fast key based subsets. If you're not familiar with these concepts, please read the [`vignette("datatable-intro", package="data.table")`](datatable-intro.html), [`vignette("datatable-reference-semantics", package="data.table")`](datatable-reference-semantics.html), and [`vignette("datatable-keys-fast-subset", package="data.table")`](datatable-keys-fast-subset.html) vignettes first. *** From ed251951912c67aef8b20e508325fbec6daf4210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Demi=C3=A1n=20Villalba?= <32423469+rikivillalba@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:57:26 -0300 Subject: [PATCH 2/3] Update vignettes/_translation_links.R Co-authored-by: Michael Chirico --- vignettes/_translation_links.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/_translation_links.R b/vignettes/_translation_links.R index 324cf77c4..8c549c96f 100644 --- a/vignettes/_translation_links.R +++ b/vignettes/_translation_links.R @@ -13,7 +13,7 @@ pattern = glob2rx(knitr::current_input(FALSE)) ) transl_lang = ifelse(dirname(translation) == ".", "en", dirname(translation)) - block = if (length(which(transl_lang != lang))) { + block = if (!all(transl_lang == lang)) { sprintf( fmt, paste(collapse = " | ", sprintf( "[%s](%s)", From d2cef04a1a81496fa43bf22d1eb8a589c6727830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Demi=C3=A1n=20Villalba?= <32423469+rikivillalba@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:57:43 -0300 Subject: [PATCH 3/3] Update vignettes/_translation_links.R Co-authored-by: Michael Chirico --- vignettes/_translation_links.R | 1 + 1 file changed, 1 insertion(+) diff --git a/vignettes/_translation_links.R b/vignettes/_translation_links.R index 8c549c96f..5e09f447c 100644 --- a/vignettes/_translation_links.R +++ b/vignettes/_translation_links.R @@ -1,4 +1,5 @@ # build a link list of alternative languages (may be character(0)) +# idea is to look like 'Other languages: en | fr | de' .write.translation.links <- function(fmt) { url = "https://rdatatable.gitlab.io/data.table/articles" path = dirname(knitr::current_input(TRUE))