MyNixOS website logo
Description

Construct Natural-Language Lists with Internationalization.

Construct language-aware lists. Make "and"-separated and "or"-separated lists that automatically conform to the user's language settings.

and

r-universe statusbadge License:MIT R buildstatus Dependencies

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?

Sys.setenv(LANGUAGE = "en_GB")
and(names)
#> [1] "John, Paul, George and Ringo"

What about other languages?

Sys.setenv(LANGUAGE = "es")
and(names)
#> [1] "John, Paul, George y Ringo"
Sys.setenv(LANGUAGE = "eu")
and(names)
#> [1] "John, Paul, George eta Ringo"
Sys.setenv(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")
Sys.setenv(LANGUAGE = "es")
and(princess_bride)
#> [1] "Vizzini, Fezzik e Inigo Montoya"

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")
Sys.setenv(LANGUAGE = "en_US")
or(outcomes)
#> [1] "win, lose, or draw"
Sys.setenv(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
Albaniansq1, 2, 3 dhe 41, 2, 3 ose 4
Amharicam1፣ 2፣ 3, እና 41፣ 2፣ 3፣ ወይም 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
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
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
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
Kyrgyzky1, 2, 3 жана 41, 2, 3 же 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 зэргийн аль нэг
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
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
Swedishsv1, 2, 3 och 41, 2, 3 eller 4
Syriacsyr‏1, 2, 3، ܘ4‎‏1, 2, 3، ܝܐ 4‎
Tamilta1, 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
Vietnamesevi1, 2, 3 và 41, 2, 3 hoặc 4
Welshcy1, 2, 3 a 41, 2, 3 neu 4
Yorubayo1, 2, 3, 41 pẹ̀lú 2, 3, tabi 4
Yoruba (Benin)yo_BJ1, 2, 3, 41 pɛ̀lú 2, 3, tabi 4

* The following English variants use an Oxford comma in addition to en_GB: en_AG, en_AI, en_AT, en_AU, en_BB, en_BE, en_BM, en_BS, en_BW, en_BZ, en_CA, en_CC, en_CH, en_CK, en_CM, en_CX, en_CY, en_DE, en_DG, en_DK, en_DM, en_ER, en_FI, en_FJ, en_FK, en_FM, en_GD, en_GG, en_GH, en_GI, en_GM, en_GY, en_HK, en_IE, en_IL, en_IM, en_IN, en_IO, en_JE, en_JM, en_KE, en_KI, en_KN, en_KY, en_LC, en_LR, en_LS, en_MG, en_MO, en_MS, en_MT, en_MU, en_MV, en_MW, en_MY, en_NA, en_NF, en_NG, en_NL, en_NR, en_NU, en_NZ, en_PG, en_PK, en_PN, en_PW, en_RW, en_SB, en_SC, en_SD, en_SE, en_SG, en_SH, en_SI, en_SL, en_SS, en_SX, en_SZ, en_TC, en_TK, en_TO, en_TT, en_TV, en_TZ, en_UG, en_VC, en_VG, en_VU, en_WS, en_ZA, en_ZM, and en_ZW.

Partially supported languages

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

LanguageCodeand example
Bodobrx1, 2, 3, आरो 4
Chakmaccp1, 2, 3 𑄃𑄳𑄃 4
Colognianksh1, 2, 3 un 4
Dogridoi1, 2, 3, ते 4
Dzongkhadz1 དང་ 2 དང་ 3 དང་ 4
Eweee1, 2, 3, kple 4
Friulianfur1, 2, 3 e 4
Igboig1, 2, 3, na 4
Kashmiriks‏1، 2، 3، تٕہ 4‎
Luxembourgishlb1, 2, 3 a(n) 4
Maithilimai1, 2, 3, और 4
Maltesemt1, 2, 3, u 4
Manipurimni1, 2, 3 অমসুং 4
Ngombajgo1, ŋ́gɛ 2, ŋ́gɛ 3, ḿbɛn ŋ́gɛ 4
Northern Samise1, 2, 3 ja 4
Osseticos1, 2, 3 ӕмӕ 4
Pashtops‏1، 2، 3، او 4‎
Sanskritsa1, 2, 3, तथा 4
Sundanesesu1, 2, 3, sareng 4
Swiss Germangsw1, 2, 3 und 4
Tatartt1, 2, 3 һәм 4
Walserwae1, 2, 3 und 4
Western Balochibgn‏1، 2، 3، و 4‎
Western Frisianfy1, 2, 3 en 4
Yakutsah1, 2, 3 уонна 4
Yiddishyi‏1, 2, 3 און 4‎
Zuluzu1, 2, 3, ne-4

Hex sticker image by Flavia Rossell Hayes.

Please note that and is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Metadata

Version

0.1.5

License

Unknown

Platforms (75)

    Darwin
    FreeBSD 13
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd13
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd13
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows