My Package {polyglot} Is Now on CRAN

A few months ago, I wrote my first package called {learner}. I finally took the time to put it on CRAN. Following the advice of a CRAN team member, I changed its name. I had to agree: it sounded like a machine learning package. So now the {learner} package is dead, long life to {polyglot}!

With {polyglot}, you can learn any two columns dataset right in the R console:

How to use {polyglot}

Let’s imagine you want to know if you can remember some basic Japanese expressions1. You would search online a two columns table and save it into the {polyglot} directory.

library(tidyverse)
library(rvest)
library(polyglot) # install.packages("polyglot")

url1 <- "https://www.omniglot.com/language/phrases/japanese.php" 

japanese <- url1 %>%
  read_html() %>%
  html_table() %>%
  .[[1]] %>%
  write_csv(path = paste0("", system.file("extdata/", package =
  "polyglot"), "Japanese_54_Basic_Expressions.csv"))

as_tibble(japanese)
## # A tibble: 54 x 2
##                     English
##                       <chr>
##  1                  Welcome
##  2 Hello (General greeting)
##  3         Hello (on phone)
##  4             How are you?
##  5  Reply to 'How are you?'
##  6         Long time no see
##  7        What's your name?
##  8           My name is ...
##  9      Where are you from?
## 10             I'm from ...
## # ... with 44 more rows, and 1 more variables: `日本語 (Japanese)` <chr>

Or maybe you would like to see if you know most of the capitals in the world.

url2 <- "https://en.wikipedia.org/wiki/List_of_national_capitals_in_alphabetical_order"

capitals <- url2 %>%
  read_html() %>%
  html_node(".wikitable") %>%
  html_table(fill = TRUE) %>%
  select(Country, City, Notes) %>%
  arrange(Country) %>%
  write_csv(path = paste0("", system.file("extdata/", package =
  "polyglot"), "List_Capital_Cities.csv"))

as_tibble(capitals)
## # A tibble: 243 x 3
##                  Country                City
##                    <chr>               <chr>
##  1              Abkhazia             Sukhumi
##  2           Afghanistan               Kabul
##  3 Akrotiri and Dhekelia Episkopi Cantonment
##  4               Albania              Tirana
##  5               Algeria             Algiers
##  6        American Samoa           Pago Pago
##  7               Andorra    Andorra la Vella
##  8                Angola              Luanda
##  9              Anguilla          The Valley
## 10   Antigua and Barbuda          St. John's
## # ... with 233 more rows, and 1 more variables: Notes <chr>

You would just have to run the learn function to learn some Japanese vocabulary.

library(polyglot)
learn() # launch the interactive learning environment

Before launching the interactive learning environment, be sure to have the appropriate encoding and that your 2 or 3 columns dataset is a CSV file.

If your R console cannot read the Japanese characters, try the following:

# Make R reading Japanese
# Sys.setlocale("LC_ALL", "Japanese")   # for Windows
# Sys.setlocale("LC_ALL", "ja_JP")       # for macOS 
# Sys.setlocale("LC_ALL", "ja_JP.utf8")  # for Modern Linux etc. 

Happy learning!

Post-scriptum

You can also try the development version of the package, which implements a simplified spaced repetition learning algorithm.

# install.packages("devtools")
devtools::install_github("lgnbhl/polyglot")
library(polyglot)
learn()

Thanks for reading!

  • For updates of recent blog posts, follow me on Twitter.
  • For reproducing my data analysis, go on my Github page.
  • Curious about what I can do for your organisation? Have a look at my Project page.
  1. For my part, all I know in Japanese is “arigato”, “konnichiwa” and “moshi moshi”. 

Leave a Comment