elizagrames / litsearchr

litsearchr is an R package to partially automate search term selection for systematic reviews using keyword co-occurrence networks. In addition to identifying search terms, it can write Boolean searches and translate them into over 50 languages.
https://elizagrames.github.io/litsearchr
101 stars 24 forks source link

get_ngrams fails for 1-grams #34

Closed luketudge closed 4 years ago

luketudge commented 4 years ago

Thanks for a great package!

Here is an example of the issue I have encountered:

get_ngrams("On the Origin of Species By Means of Natural Selection", n=1)

I get an error coming from line 138 of generic_text_functions.R complaining about the input being dimensionless.

I think this is because whereas R turns ngram_df[, 1:n] into a dataframe when n is greater than 1 it turns it into a single value when n is 1, and apply() can't handle this. So maybe this line should have something like:

ngram_df[, 1:n, drop=FALSE]

To keep the 1-gram case compatible with apply(), as described here.