Watts-College / cpp-527-fall-2021

A course shell for CPP 527 Foundations of Data Science II
https://watts-college.github.io/cpp-527-fall-2021/
2 stars 6 forks source link

Week04- Library(Quanteda) #32

Open AhmedRashwanASU opened 2 years ago

AhmedRashwanASU commented 2 years ago

Good Day Prof ,

After installing (quanteda) Package, when trying to load the library(quanteda) it keeps loading for hours then not loaded, any idea what can be the reason for this issue?

lecy commented 2 years ago

I'm not sure, can you close R Studio and re-open it without problems? There was a similar problem with the geojsonio with the new version of R (4.0), but it was resolved by 4.0.5.

What is your session info?

sessionInfo()
AhmedRashwanASU commented 2 years ago

R version 4.0.2 (2020-06-22)

I have just updated my R version to 4.1.1 (2021-08-10)

and installed and loaded the quanteda and it worked, Thanks Prof!

voznyuky commented 2 years ago

Professor Lecy, I'm getting this message:

Error in textstat_frequency(., n = 10) : 
  could not find function "textstat_frequency"

Even though I have installed and library() the quanteda package. I have restarted R and nothing changed.

It's from this:

# find frequently co-occuring words (typically compound words)
ngram2 <- tokens_ngrams( tokens, n=2 ) %>% dfm()
ngram2 %>% textstat_frequency( n=10 )
lecy commented 2 years ago

@voznyuky I'm not sure why you would get that error. Is the rest of the package working?

Do you get any errors when you install it?

detach( "package:quanteda" )  # closes the package so not locked
remove.packages( "quanteda" ) # deletes from your computer 
install.packages( "quanteda" )

Which version of R are you using?

mtwelker commented 2 years ago

@voznyuky , I got the same error, so I installed the following packages (which were mentioned at the beginning of the quanteda Quick Start guide):

quanteda.textmodels
quanteda.textstats
quanteda.textplots  # (The Quick Start guide said quanteda.textplot, but I could only find quanteda.textplot**s**)

That did the trick for me.

voznyuky commented 2 years ago

@lecy R version 4.1.0 (2021-05-18) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Big Sur 11.3.1

I uninstalled it and re-installed it and it still didn't work, but @mtwelker helped me out.

@mtwelker that was the trick, thank you so much!!!

lecy commented 2 years ago

Thanks @mtwelker !

I've added this to the lab to be more explicit about the installation steps:

quanteda.bundle <- c( "quanteda", "quanteda.textmodels",
                      "quanteda.textstats", "quanteda.textplots" )
install.packages( quanteda.bundle )
lecy commented 2 years ago

It looks like they have started factoring the quanteda package, which doesn't surprise me because it is a very large library that does a lot of things.

The textstat_frequency() function used to be a part of core quanteda:

https://www.rdocumentation.org/packages/quanteda/versions/2.1.2/topics/textstat_frequency

But now is bundled under quanteda.textstats.

You refactor code or packages when they grow large and become unwieldy to manage and maintain. Factoring involves re-grouping into meaningful parts, often removing redundancy or unnecessary dependencies.

voznyuky commented 2 years ago

I suspected that could've been the reason (separation) but wasn't able to find anything via google search, but glad Michelle knew the trick.

sandralili commented 2 years ago

Hello,

I struggled with the same problem, so thank you all! Also, if someone else is facing this problem, each library needs to be called. library ( quanteda ) library ( quanteda.textmodels ) library ( quanteda.textplots ) library ( quanteda.textstats)

or

library (quanteda.bundle)

lecy commented 2 years ago

You can use either load step - you can reference a bunch of package with the same library() command. But you need to include the vector that lists the packages then. The quarter.bundle is just the vector name, not to be confused with the “tidyverse” package convention, which is just a package that loads a bunch of other packages.

sandralili commented 2 years ago

Sounds good, thanks Dr. @lecy !