7

Using the qdap::polarity() function can sometimes run into the error:

Error in derive_pubkey(key) : RAW() can only be applied to a 'raw', not a 'list'

I'm fairly certain this is due qdap's key class conflicting with the openssl package's key class (since derive_pubkey() from openssl is referenced in the error msg).

The error happens when openssl appears in the loaded via a namespace (and not attached): section of sessionInfo(), and it seems to throw off method dispatch for the key class and cause the error.

I've only been able to fix the error by restarting my R session. Is there a way to remove openssl's footprint from the session to fix this issue? Or is there another way to avoid this issue without restarting R?

recreation of error

> successful      <- qdap::polarity("testing")
> load_openssl_ns <- body(openssl:::print.key)
> fails           <- qdap::polarity("testing")
Error in derive_pubkey(key) : 
  RAW() can only be applied to a 'raw', not a 'list'
Adam Spannbauer
  • 2,707
  • 1
  • 17
  • 27

1 Answers1

5

For a dirty fix run

`[[.qdap_hash` <- `[[.data.frame`

Checking...

> qdap::polarity("test")
  all total.sentences total.words ave.polarity sd.polarity stan.mean.polarity
1 all               1           1            0          NA                 NA
> library(openssl)
Warning message:
package ‘openssl’ was built under R version 3.3.3 
> qdap::polarity("test")
Error in derive_pubkey(key) : 
  RAW() can only be applied to a 'raw', not a 'list'
> `[[.qdap_hash` <- `[[.data.frame`
> qdap::polarity("test")
  all total.sentences total.words ave.polarity sd.polarity stan.mean.polarity
1 all               1           1            0          NA                 NA
> 

The offending line in polarity is words <- c(posneg, alter[[1]])

The object alter gets created with alter_env which creates an object which has classes "qdap_hash", "key", ...

qdap_hash doesn't have it's own '[[' method so it checks to see if key has a '[[' method which it typically doesn't. Once openssl gets loaded there is a [[ method for key so it uses that and gives the error since it isn't in the form expected. If we define our own method for qdap_hash that gets called before even attempting to use [[.key so we bypass the issue. The author of qdap has been informed of the issue and the possible fix.

Dason
  • 60,663
  • 9
  • 131
  • 148
  • 3
    thanks for the find. I have added this to the export of qdapTools which will fix for all other packages that rely on qdapTools. The dev version of qdapTools can be installed with: `if (!require("pacman")) install.packages("pacman"); p_load_current_gh('trinker/qdapTools')` – Tyler Rinker Jul 19 '17 at 18:26
  • @TylerRinker Any ideas when your next push to CRAN will be for qdap? – Dason Jul 19 '17 at 18:31