Document as.IDate() behaviour with fractional dates

未關閉 適合新手
#7,952 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
1/5
預估耗時
1 小時以內
新手友好度
78/100
Issue 類型
文件
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
r
領域
documentation

研究方向

此行為來自 as.IDate() 對 Date 輸入的處理,它會經過 as.integer(),因此朝 epoch 方向進位;報告中的範例顯示了先向下取整的差異。請找到 as.IDate 的文件(其 Rd 檔或 roxygen 區塊),並加入一段簡短說明:帶小數的 Date 值會朝零截斷,並附上 issue 中的範例。當說明頁面載明了捨入方式且範例仍能執行時,即視為完成。

由索引模型根據 Issue 內容生成。

描述

beginner-task

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.

主要語言
R
星號
3.9k
分支
1.1k
平均合併
1 天 8 小時
30 天內合併 PR
14

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

Rdatatable/data.table 的其他 Issue

查看 Rdatatable/data.table 的全部 Issue

相似的 Issue

更多 R Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。