Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid class name conflict with a package "loaded via a namespace (and not attached)" (qdap & openssl)

Tags:

r

qdap

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'
like image 916
Adam Spannbauer Avatar asked Jul 19 '17 17:07

Adam Spannbauer


People also ask

How many naming conflicts are there on a page?

If a page contains N components, there will be at least N + 1 naming conflicts. As far as one of our specific projects is concerned, there have been at least 500 + conflicts. The or [as] solution does not solve the intrinsic conflict problem.

When do the names of two Java classes conflict?

As you can guess, the names conflict when both classes are referenced in the same Java file. com.myapp.model (package) - Device (class) - ... com.myapp.data (package) - Device (class) - ... We had a debate on what's the best practice to treat these cases and the following options came up:

Why do classes with the same name conflict with each other?

We've divided our business logic into multiple packages. some of which have classes with identical names. As you can guess, the names conflict when both classes are referenced in the same Java file.

Why does Java have a package naming convention?

This type of problem is precisely why Java uses the package naming convention that it does. It prevents these sorts of problems, whether it's two teams in the same company or two teams on opposite sides of the earth. Show activity on this post.


1 Answers

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.

like image 156
Dason Avatar answered Sep 20 '22 17:09

Dason