randy3k / collections

High-performance container datatypes for R
https://randy3k.github.io/collections
Other
103 stars 3 forks source link

Information about the type of data structure from object. #14

Closed 24sharkS closed 4 years ago

24sharkS commented 4 years ago

I am using dict() object in a function and want to perform check to make sure that the argument passed to the function is of dict type.

The class function doesn't provide this information.

d <- dict(list(a = 1,b = 2))  
class(d)
[1] "environment"

Any workaround for this issue?

24sharkS commented 4 years ago

@randy3k is there any function for this purpose?

randy3k commented 4 years ago

That's a valid request. There is no such thing now.

The closest thing is

is.environment(d) && identical(parent.env(d), asNamespace("collections"))

But it only checks if the object is from collections, it doesn't check if it is a dict or other containers.

24sharkS commented 4 years ago

In addition to above we can also do something like this, which will confirm the type too.

strsplit(capture.output(d$print)," ")[[1]][1] == "dict"
randy3k commented 4 years ago

closed by b308f8f