Search code examples
rquanteda

How do you use a LIWC-formatted dictionary with the R package Quanteda?


As LIWC software and dictionaries are proprietary, I was pleased to see they seemed to play well with the still-in-development but excellent R package Quanteda.

The documentation for the R package Quanteda demonstrates its use with a LIWC-format dictionary, as does this SO post.

I purchased LIWC 2015 but can't figure out how to export the dictionary outside the application other than as a PDF.


Solution

  • Edited by request of Receptivity ("the commercial side of LIWC")

    I will not advise you on how to extract the English LIWC 2015 dictionary from the Java Archive (.jar) file that contains the software which requires a purchase.

    Unlike in previous versions of the LIWC software, the dictionary files are not distributed directly with the software. But using your legally purchased serial number to log in, you can download the non-English dictionaries from LIWC2007 and LIWC2001 (depending on the language) from http://dictionaries.liwc.net, which includes German, Dutch, Italian, Russian, French, and Spanish versions.

    If you have a dictionary formatted in the same manner as the LIWC dictionaries, for instance the Moral Foundations dictionary, then this will work:

    require(quanteda)
    mfdict <- dictionary(file = "http://www.moralfoundations.org/sites/default/files/files/downloads/moral%20foundations%20dictionary.dic", 
                        format = "LIWC")
    

    which loads and converts the Moral Foundations dictionary into the quanteda format. You can use the dictionary in constructing a document-feature matrix using

    dfm(x, dictionary = mfdict)