Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

as.period doesn't convert to specified time units if x is a vector #349

Closed
mgacc0 opened this issue Oct 6, 2015 · 1 comment
Closed

Comments

@mgacc0
Copy link

mgacc0 commented Oct 6, 2015

ints <- c(
  new_interval(ymd("2001-01-01"), ymd("2002-01-01")),
  new_interval(ymd("2001-01-01"), ymd("2004-01-01"))
)
as.period(ints)
# [1] "1y 0m 0d 0H 0M 0S" "3y 0m 0d 0H 0M 0S"

as.period converts correctly to the specified time units if the variable is a scalar:

as.period(ints[1], "days")
# [1] "365d 0H 0M 0S"

But it shows an error if it's a vector:

as.period(ints, "days")
# Error in initialize(value, ...) : 
#   invalid names for slots of class “Period”: day1, day2

I would prefer not having to do something like

ans <- Map(function(x) as.period(x, "days"), ints)
ans
# [[1]]
# [1] "365d 0H 0M 0S"
# 
# [[2]]
# [1] "1095d 0H 0M 0S"

And, also, why does this happen?

unlist(ans)
# [1] 0 0

Should be necessary to implement the unlist function for Interval objects?

(Thanks in advance.)

@mgacc0 mgacc0 changed the title as.period doesn't convert to units if there if x is a vector of intervals as.period doesn't convert to units if x is a vector Oct 6, 2015
@mgacc0 mgacc0 changed the title as.period doesn't convert to units if x is a vector as.period doesn't convert to specified time units if x is a vector Oct 6, 2015
@vspinu vspinu closed this as completed in 333b8c4 Oct 6, 2015
@vspinu
Copy link
Member

vspinu commented Oct 6, 2015

Thanks! Have no idea how we got so far without noticing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants