berndbischl / BBmisc

Other
20 stars 7 forks source link

ensureVector() not so integer friendly #52

Closed jakob-r closed 9 years ago

jakob-r commented 9 years ago

Please check if that is the desired outcome

> x = 3
> ensureVector(x, n = 3)
[1] 3 3 3
> ensureVector(x, n = 3, cl = "integer")
[1] 3
> ensureVector(x, n = 3, cl = "numeric")
[1] 3 3 3
berndbischl commented 9 years ago

Well it does what the docs say. If it has the class, it is "pumped up" to a vector. 3 is not "integer".

The real issue seems to be that you dont use checkmate. if you ensure that your 3 is actually a 3L after arg checks, this problem disappears.

so like f(x) x = asInt(x) ensureVector(x, 3, "integer")

I guess this might be the better solution than to complicate ensureVec with another special case, which is also really hard to define.

Either agree / close or tell me why i am wrong

jakob-r commented 9 years ago

Sound fine but then and I agree but on the other hand ensureVector does not ensure anything.

> ensureVector("hello", n = 3, cl = "integer")
[1] "hello"

But it's documented and I am fine

berndbischl commented 9 years ago

it "ensures" it for a given class. or for all objects, it you leave that out.

(you often want ONLY to transform certain objects into a list and let others pass)