jeroen / openssl

OpenSSL bindings for R
Other
63 stars 20 forks source link

as.character doesn't cast correctly #60

Closed dpmccabe closed 5 years ago

dpmccabe commented 5 years ago
> str(as.character(openssl::md5("")))
Classes 'hash', 'md5'  chr "d41d8cd98f00b204e9800998ecf8427e"
> class(as.character(openssl::md5("")))
[1] "hash" "md5" 

This creates problems when other packages examine the class of an object expected to be a character:

> jsonlite::toJSON(as.character(openssl::md5("")))
Error: No method asJSON S3 class: md5
hongooi73 commented 5 years ago

You can use unclass instead of as.character for this specific use case:

> jsonlite::toJSON(unclass(openssl::md5("")))
["d41d8cd98f00b204e9800998ecf8427e"]