knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
syn
is a zero dependency R package that lists synonyms and antonyms.
There are two main functions:
syn("great")
Returns synonyms of "great"ant("great")
Returns antonyms of "great".syn
and ant
take one word as input. To return synonyms for many words, use the plural form: syn
s, and ant
s
syns(c("great", "excellent")
Returns named list of synonyms of "great", and "excellent"ants(c("great", "excellent")
Returns named list of antonyms of "great", and "excellent"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)
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)}!")
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)
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"))
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
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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.