knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

syn

R-CMD-check Coverage status Project Status: Active – The project has reached a stable, usable state and is being actively developed. CRAN_Status_Badge CRAN Logs

syn is a zero dependency R package that lists synonyms and antonyms.

There are two main functions:

syn and ant take one word as input. To return synonyms for many words, use the plural form: syns, and ants

Example: Synonyms for "cool"

The syn function returns all synonyms for a given word:

Let's look at synonyms for "cool":

library(syn)

syn_cool <- syn("cool")

head(syn_cool)
tail(syn_cool)

Wow, there are a lot! How many are there?

length(syn_cool)

Wow! There are r length(syn_cool) synonyms for cool. That's...r syn("cool", 1), I guess.

You can also provide it a number of words to return with the n_words argument, which will randomly select the number of words given

syn("awesome", 1)
syn("awesome", 2)
syn("awesome", 5)

Example: Creating a sentence

OK cool, let's use these in a sentence, using the glue package. Which of these better?

glue::glue("This is really cool!")
glue::glue("This is really {syn('cool', 1)}!")
glue::glue("This is really {syn('cool', 10)}!")

Using multiple words with syns

You can generate synonyms for multiple words with the syns function. This takes a vector of words, returning a named list

syns_good_evil <- syns(c("good", "evil"))
str(syns_good_evil)

You can also provide n_words for syns, and it will return a random selection of the words of that number.

syns(c("good", "evil"),
     n_words =  10)

Example: Antonyms (under development)

To create antonyms, use ant and ants, which have the same inputs as syn. However, at this stage, the number of antonyms available for use by ant is small.

ant("good")
ant("good",1)

ant("strong")
ants(c("good", "evil"))

ants(c("good", "evil"), n_words = 5)

ants(c("strong", "weak"))

Example: Filtering by the number of words in a synonym

Let's say that you want to filter something down to those synonyms that only contain one word. You can use the n_words argument, which calculates the number of words for each

syn_end <- syn("end")

n_words(syn_end)
syn_end_l1 <- syn_end[n_words(syn_end) <= 1]
syn_end_l1

Code of Conduct

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



ropenscilabs/syn documentation built on Feb. 3, 2024, 4:32 a.m.