hadron icon indicating copy to clipboard operation
hadron copied to clipboard

tex.catwitherror does not work well with vectors

Open kostrzewa opened this issue 5 years ago • 5 comments

There should probably be some internal loops, such that vector-valued quantities can be dealt with. At present, this fails because the conditionals don't play nice with vectors of x and dx.

kostrzewa avatar Feb 20 '20 20:02 kostrzewa

There should probably be some internal loops, such that vector-valued quantities can be dealt with. At present, this fails because the conditionals don't play nice with vectors of x and dx.

well, it can be used with apply...!

urbach avatar Feb 20 '20 20:02 urbach

well, it can be used with apply...!

That's true, but it cannot be used with dplyr::mutate like so:

data <- data.frame(val = [...], err = [...])
data <- dplyr::mutate(data, tex = tex.catwitherror(x = val, dx = err))

which is a really handy function for adding new columns to data frames based on existing columns.

kostrzewa avatar Feb 20 '20 20:02 kostrzewa

I always just use mapply:

mutate(tex = mapply(tex.catwitherror, val, err))

martin-ueding avatar Feb 21 '20 11:02 martin-ueding

It would be trivial to have a the current non-vectorized version as tex.catwitherror.scalar and then have a new tex.catwitherror which just calles the implementation with mapply. The problem is that currently it is allowed to pass value and error as a two-element vector as the first argument. This would become inconsistent then.

martin-ueding avatar Feb 21 '20 11:02 martin-ueding

It would be trivial to have a the current non-vectorized version as tex.catwitherror.scalar and then have a new tex.catwitherror which just calles the implementation with mapply. The problem is that currently it is allowed to pass value and error as a two-element vector as the first argument. This would become inconsistent then.

Well, rather the new one would get a different name, wouldn't it?

urbach avatar Feb 22 '20 14:02 urbach