Learn R Programming

and

and constructs language-aware lists in R. It extends the functionality of functions like knitr::combine_words() and glue::glue_collapse() to make and-separated and or-separated lists that automatically conform to the user’s R language settings.

Installation

You can install the released version of and from CRAN with:

install.packages("and")

or the development version of and from GitHub with:

# install.packages("pak")
pak::pkg_install("rossellhayes/and")

Usage

and() creates “and”-separated lists from vectors.

names <- c("John", "Paul", "George", "Ringo")
and(names)
#> [1] "John, Paul, George, and Ringo"

But the Oxford comma is less common in other varieties of English, what happens if I change my R language to British English?

local_language("en_GB")
and(names)
#> [1] "John, Paul, George and Ringo"

What about other languages?

local_language("es")
and(names)
#> [1] "John, Paul, George y Ringo"

local_language("eu")
and(names)
#> [1] "John, Paul, George eta Ringo"

local_language("ko")
and(names)
#> [1] "John, Paul, George 및 Ringo"

Handling the nuances

Creating a list is not as simple as putting a different word between the last two items. For example, in Spanish, the word for and changes if the next word starts with an ⟨i⟩ or ⟨y⟩:

princess_bride <- c("Vizzini", "Fezzik", "Inigo Montoya")
local_language("es")
and(princess_bride)
#> [1] "Vizzini, Fezzik e Inigo Montoya"

Special rules like this are implemented for Spanish, Italian, Welsh, and Luxembourgish.

or-separated lists

Everything and() can do or() can do better. Just use or() to create or-separated lists with all the same contextual awareness.

outcomes <- c("win", "lose", "draw")
local_language("en_US")
or(outcomes)
#> [1] "win, lose, or draw"

local_language("ja")
or(outcomes)
#> [1] "win、lose、またはdraw"

Hardcoding language

Don’t want the language of you string to depend on the user’s environment variables? You can explicitly set the language using the language argument.

and(names, language = "en_US")
#> [1] "John, Paul, George, and Ringo"

and(names, language = "en_GB")
#> [1] "John, Paul, George and Ringo"

and(names, language = "es")
#> [1] "John, Paul, George y Ringo"

and(names, language = "fr")
#> [1] "John, Paul, George et Ringo"

Languages

Fully supported languages

LanguageCodeand exampleor example
Afrikaansaf1, 2, 3 en 41, 2, 3 of 4
Akanak1, 2, 3, ne 41, 2, 3, anaa 4
Albaniansq1, 2, 3 dhe 41, 2, 3 ose 4
Amharicam1፣ 2፣ 3 እና 41፣ 2፣ 3 ወይም 4
Aniiblo1, 2, 3 na 41, 2, 3 koo 4
Arabicar‏1 و2 و3 و4‎‏1 أو 2 أو 3 أو 4‎
Armenianhy1, 2, 3 և 41, 2, 3 կամ 4
Assameseas1, 2, 3 আৰু 41, 2, 3 বা 4
Asturianast1, 2, 3 y 41, 2, 3 o 4
Azerbaijaniaz1, 2, 3 və 41, 2, 3, yaxud 4
Banglabn1, 2, 3 এবং 41, 2, 3, বা 4
Basqueeu1, 2, 3 eta 41, 2, 3 edo 4
Belarusianbe1, 2, 3 і 41, 2, 3 ці 4
Bosnianbs1, 2, 3 i 41, 2, 3 ili 4
Bretonbr1, 2, 3 ha 41, 2, 3 pe 4
Bulgarianbg1, 2, 3 и 41, 2, 3 или 4
Burmesemy1 - 2 - 3နှင့် 41 - 2 - 3 သို့မဟုတ် 4
Cantoneseyue1、2、3同41、2、3 或 4
Catalanca1, 2, 3 i 41, 2, 3 o 4
Cebuanoceb1, 2, 3, ug 41, 2, 3, o 4
Cherokeechr1, 2, 3, ᎠᎴ 41, 2, 3, ᎠᎴᏱᎩ 4
Chinesezh1、2、3和41、2、3或4
Chuvashcv1, 2, 3 тата 41, 2, 3 е 4
Croatianhr1, 2, 3 i 41, 2, 3 ili 4
Czechcs1, 2, 3 a 41, 2, 3 nebo 4
Danishda1, 2, 3 og 41, 2, 3 eller 4
Dutchnl1, 2, 3 en 41, 2, 3 of 4
English (with Oxford comma)en1, 2, 3, and 41, 2, 3, or 4
English (without Oxford comma)en_GB et al.*1, 2, 3 and 41, 2, 3 or 4
Estonianet1, 2, 3 ja 41, 2, 3 või 4
Faroesefo1, 2, 3, og 41, 2, 3, ella 4
Filipinofil1, 2, 3, at 41, 2, 3, o 4
Finnishfi1, 2, 3 ja 41, 2, 3 tai 4
Frenchfr1, 2, 3 et 41, 2, 3 ou 4
Galiciangl1, 2, 3 e 41, 2, 3 ou 4
Georgianka1, 2, 3 და 41, 2, 3 ან 4
Germande1, 2, 3 und 41, 2, 3 oder 4
Greekel1, 2, 3 και 41, 2, 3 ή 4
Gujaratigu1, 2, 3 અને 41, 2, 3, અથવા 4
Haitian Creoleht1, 2, 3 et 41, 2, 3 ou 4
Hausaha1, 2, 3, da 41, 2, 3 ko 4
Hebrewhe‏1, 2, 3 ו4‎‏1, 2, 3 או 4‎
Hindihi1, 2, 3, और 41, 2, 3 या 4
Hungarianhu1, 2, 3 és 41, 2, 3 vagy 4
Icelandicis1, 2, 3 og 41, 2, 3 eða 4
Igboig1, 2, 3, na 41, 2, 3, ma ọ bụ 4
Indonesianid1, 2, 3, dan 41, 2, 3, atau 4
Interlinguaia1, 2, 3 e 41, 2, 3 o 4
Irishga1, 2, 3 agus 41, 2, 3 nó 4
Italianit1, 2, 3 e 41, 2, 3 o 4
Japaneseja1、2、3、41、2、3、または4
Javanesejv1, 2, 3, lan 41, 2, 3, utowo 4
Kabuverdianukea1, 2, 3 i 41, 2, 3 o 4
Kaingangkgp1, 2, 3 kar 41, 2, 3 ketũmỹr 4
Kangrixnr1, 2, 3, कने 41, 2, 3 या 4
Kannadakn1, 2, 3, ಮತ್ತು 41, 2, 3, ಅಥವಾ 4
Kazakhkk1, 2, 3, 41, 2, 3, не болмаса 4
Khmerkm1, 2, 3 និង 41, 2, 3 ឬ 4
Konkanikok1, 2, 3, 41, 2, 3, वा 4
Koreanko1, 2, 3 및 41, 2, 3 또는 4
Kurdishku1, 2, 3 û 41, 2, 3 an 4
Kuvikxv1, 2, 3, aḍe 41, 2, 3, aadtẽ 4
Kyrgyzky1, 2, 3 жана 41, 2, 3 же 4
Ladinlld1, 2, 3 y 41, 2, 3 o 4
Laolo1, 2, 3, 41, 2, 3 ຫຼື 4
Latvianlv1, 2, 3 un 41, 2, 3 vai 4
Lithuanianlt1, 2, 3 ir 41, 2, 3 ar 4
Lower Sorbiandsb1, 2, 3 a 41, 2, 3 abo 4
Macedonianmk1, 2, 3 и 41, 2, 3 или 4
Malayms1, 2, 3 dan 41, 2, 3, atau 4
Malayalamml1, 2, 3, 4 എന്നിവ1, 2, 3, അല്ലെങ്കിൽ 4
Marathimr1, 2, 3 आणि 41, 2, 3, किंवा 4
Mongolianmn1, 2, 3, 41, 2, 3, 4 зэргийн аль нэг
Māorimi1, 2, 3, 41, 2, 3, 4 rānei
Nepaline1,2, 3 र 41, 2, 3, वा 4
Nheengatuyrl1, 2, 3 asuí 41, 2, 3 u 4
Nigerian Pidginpcm1, 2, 3, an 41, 2, 3 ọ 4
Norwegianno1, 2, 3 og 41, 2, 3 eller 4
Norwegian Bokmålnb1, 2, 3 og 41, 2, 3 eller 4
Norwegian Nynorsknn1, 2, 3 og 41, 2, 3 eller 4
Odiaor1, 2, 3, ଓ 41, 2, 3 କିମ୍ବା 4
Persianfa‏1،‏ 2،‏ 3، و 4‎‏1،‏ 2،‏ 3، یا 4‎
Polishpl1, 2, 3 i 41, 2, 3 lub 4
Portuguesept1, 2, 3 e 41, 2, 3 ou 4
Punjabipa1, 2, 3 ਅਤੇ 41, 2, 3 ਜਾਂ 4
Quechuaqu1, 2, 3, 41, 2, 3, utaq 4
Romanianro1, 2, 3 și 41, 2, 3 sau 4
Romanshrm1, 2, 3 e 41, 2, 3 u 4
Russianru1, 2, 3 и 41, 2, 3 или 4
Sardiniansc1, 2, 3 e 41, 2, 3 o 4
Scottish Gaelicgd1, 2, 3 agus 41, 2, 3 no 4
Serbiansr1, 2, 3 и 41, 2, 3 или 4
Sichuan Yiii1、2、3ꌋꆀ41、2、3ꅀ4
Sindhisd‏1، 2، 3، ۽ 4‎‏1, 2, 3, يا 4‎
Sinhalasi1, 2, 3, සහ 41, 2, 3, හෝ 4
Slovaksk1, 2, 3 a 41, 2, 3 alebo 4
Sloveniansl1, 2, 3 in 41, 2, 3 ali 4
Somaliso1, 2, 3 iyo 41, 2, 3 ama 4
Spanishes1, 2, 3 y 41, 2, 3 o 4
Swahilisw1, 2, 3 na 41, 2, 3 au 4
Swampy Creecsw1, 2, 3, 41, 2, 3, ᐊᐍᑳ 4
Swedishsv1, 2, 3 och 41, 2, 3 eller 4
Syriacsyr‏1 ܘ2 ܘ3 ܘ4‎‏1 ܐܘ 2 ܐܘ 3 ܐܘ 4‎
Tajiktg1, 2, 3, 41, 2, 3, ё 4
Tamilta1, 2, 3 மற்றும் 41, 2, 3 அல்லது 4
Tatartt1, 2, 3 һәм 41, 2, 3, яки 4
Telugute1, 2, 3 మరియు 41, 2, 3 లేదా 4
Thaith1 2 3 และ41, 2, 3 หรือ 4
Tigrinyati1፣ 2፣ 3ን 4ን1፣ 2፣ 3 ወይ 4
Tonganto1 mo 2 mo 3 mo 41, 2, 3, pē 4
Turkishtr1, 2, 3 ve 41, 2, 3 veya 4
Turkmentk1, 2, 3 we 41, 2, 3 ýa-da 4
Ukrainianuk1, 2, 3 і 41, 2, 3 або 4
Upper Sorbianhsb1, 2, 3 a 41, 2, 3 abo 4
Urduur‏1، 2، 3، اور 4‎‏1، 2، 3، یا 4‎
Uzbekuz1, 2, 3 va 41, 2, 3 yoki 4
Venetianvec1, 2, 3 e 41, 2, 3, o 4
Vietnamesevi1, 2, 3 và 41, 2, 3 hoặc 4
Welshcy1, 2, 3 a 41, 2, 3 neu 4
Yorubayo1, 2, 3, 41, 2, 3, tabi 4
Yoruba (Benin)yo_BJ1, 2, 3, 41 pɛ̀lú 2, 3, tabi 4

* The following English variants use no Oxford comma: AG, AI, AT, AU, BB, BE, BM, BS, BW, BZ, CA, CC, CH, CK, CM, CX, CY, CZ, DE, DG, DK, DM, ER, ES, FI, FJ, FK, FM, FR, GB, GD, GG, GH, GI, GM, GS, GY, HK, HU, ID, IE, IL, IM, IN, IO, IT, JE, JM, KE, KI, KN, KY, LC, LR, LS, MG, MO, MS, MT, MU, MV, MW, MY, NA, NF, NG, NL, NO, NR, NU, NZ, PG, PK, PL, PN, PT, PW, RO, RW, SB, SC, SD, SE, SG, SH, SI, SK, SL, SS, SX, SZ, TC, TK, TO, TT, TV, TZ, UG, VC, VG, VU, WS, ZA, ZM, and ZW.

Partially supported languages

Partially supported languages generally localize and() but not or().

LanguageCodeand example
Bodobrx1, 2, 3, आरो 4
Chakmaccp1, 2, 3

Copy Link

Version

Install

install.packages('and')

Monthly Downloads

609

Version

0.1.7

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Alexander Rossell Hayes

Last Published

December 1st, 2025

Functions in and (0.1.7)

and_languages

Supported languages
set_language

Change the language of the current R environment
and

Combine a vector into a natural language string
and-package

and: Construct Natural-Language Lists with Internationalization