Document as.IDate() behaviour with fractional dates

Open Beginner friendly
#7,952 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
78/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Active
Tech stack
r
Domain
documentation

Research direction

The behaviour comes from as.IDate() for Date input, which goes through as.integer() and so rounds toward the epoch; the report's examples show the difference from flooring first. Find the as.IDate documentation (its Rd file or roxygen block) and add a short note that fractional Date values are truncated toward zero, with the example from the issue. Done when the help page states the rounding and the examples still run.

Written by the indexing model from the issue text.

Description

as.IDate() calls as.integer() on Date input which means fractional dates are rounded towards the unix epoch. This leads to the following behaviour.

(origin <- .Date(0))
#> [1] "1970-01-01"
(dates <- c(origin - 0.2, origin + 0.2))
#> [1] "1969-12-31" "1970-01-01"
data.table::as.IDate(dates)
#> [1] "1970-01-01" "1970-01-01"

# I believe this is being done internally with the 'Date' method
as.integer(dates)
#> [1] 0 0

# Alternative is to floor first
as.integer(floor(unclass(dates)))
#> [1] -1  0

To me flooring is the more 'expected' result so (assuming it is not something you wish to change) is it worth pointing this behaviour out explicitly in the documentation. Apologies if I've missed this but couldn't see it mentioned.

Dominant language
R
Stars
3.9k
Forks
1.1k
Avg merge
1d 8h
Merged PRs (30d)
14

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rdatatable/data.table

All issues in Rdatatable/data.table

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.