mirror of
https://github.com/agdamsbo/daDoctoR.git
synced 2024-11-23 20:30:21 +01:00
age_calc update to handle vector of enddates 2021-11-08 11:00:30
This commit is contained in:
parent
21391d9392
commit
bb0d627259
@ -1,6 +1,6 @@
|
|||||||
Package: daDoctoR
|
Package: daDoctoR
|
||||||
Title: Functions For Health Research
|
Title: Functions For Health Research
|
||||||
Version: 0.21.16
|
Version: 0.21.17
|
||||||
Year: 2021
|
Year: 2021
|
||||||
Author: Andreas Gammelgaard Damsbo <agdamsbo@pm.me>
|
Author: Andreas Gammelgaard Damsbo <agdamsbo@pm.me>
|
||||||
Maintainer: Andreas Gammelgaard Damsbo <agdamsbo@pm.me>
|
Maintainer: Andreas Gammelgaard Damsbo <agdamsbo@pm.me>
|
||||||
@ -10,4 +10,4 @@ Suggest: shiny
|
|||||||
License: GPL (>= 2)
|
License: GPL (>= 2)
|
||||||
Encoding: UTF-8
|
Encoding: UTF-8
|
||||||
LazyData: true
|
LazyData: true
|
||||||
RoxygenNote: 7.1.1
|
RoxygenNote: 7.1.2
|
||||||
|
11
R/age_calc.R
11
R/age_calc.R
@ -9,7 +9,7 @@
|
|||||||
#' @export
|
#' @export
|
||||||
#' @examples
|
#' @examples
|
||||||
#' ##Kim Larsen (cpr is known from album)
|
#' ##Kim Larsen (cpr is known from album)
|
||||||
#' dob<-dob_extract_cpr("231045-0637")
|
#' dob<-daDoctoR::dob_extract_cpr("231045-0637")
|
||||||
#' date<-as.Date("2018-09-30")
|
#' date<-as.Date("2018-09-30")
|
||||||
#' trunc(age_calc(dob,date))
|
#' trunc(age_calc(dob,date))
|
||||||
|
|
||||||
@ -19,9 +19,15 @@ age_calc<-function (dob, enddate = Sys.Date(), units = "years", precise = TRUE)
|
|||||||
if (!inherits(dob, "Date") | !inherits(enddate, "Date")) {
|
if (!inherits(dob, "Date") | !inherits(enddate, "Date")) {
|
||||||
stop("Both dob and enddate must be Date class objects")
|
stop("Both dob and enddate must be Date class objects")
|
||||||
}
|
}
|
||||||
if (enddate < dob) {
|
|
||||||
|
if (length(dob)==1 && enddate < dob) {
|
||||||
stop("End date must be a date after date of birth")
|
stop("End date must be a date after date of birth")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (length(dob)>1 && any(enddate < dob)) {
|
||||||
|
stop("End date must be a date after date of birth")
|
||||||
|
}
|
||||||
|
|
||||||
start <- as.POSIXlt(dob)
|
start <- as.POSIXlt(dob)
|
||||||
end <- as.POSIXlt(enddate)
|
end <- as.POSIXlt(enddate)
|
||||||
if (precise) {
|
if (precise) {
|
||||||
@ -74,6 +80,7 @@ age_calc<-function (dob, enddate = Sys.Date(), units = "years", precise = TRUE)
|
|||||||
result <- years
|
result <- years
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
stop("Unrecognized units. Please choose years, months, or days.")
|
stop("Unrecognized units. Please choose years, months, or days.")
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ For age calculations.
|
|||||||
}
|
}
|
||||||
\examples{
|
\examples{
|
||||||
##Kim Larsen (cpr is known from album)
|
##Kim Larsen (cpr is known from album)
|
||||||
dob<-dob_extract_cpr("231045-0637")
|
dob<-daDoctoR::dob_extract_cpr("231045-0637")
|
||||||
date<-as.Date("2018-09-30")
|
date<-as.Date("2018-09-30")
|
||||||
trunc(age_calc(dob,date))
|
trunc(age_calc(dob,date))
|
||||||
}
|
}
|
||||||
|
10
packing.R
10
packing.R
@ -9,3 +9,13 @@ devtools::document()
|
|||||||
# Inspiration: "https://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/"
|
# Inspiration: "https://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/"
|
||||||
|
|
||||||
# Author@R: person("Andreas", "Gammelgaard Damsbo", email = "agdamsbo@pm.me", role = c("cre", "aut"))
|
# Author@R: person("Andreas", "Gammelgaard Damsbo", email = "agdamsbo@pm.me", role = c("cre", "aut"))
|
||||||
|
|
||||||
|
|
||||||
|
# Commit and push
|
||||||
|
commit_message<-"age_calc update to handle vector of enddates"
|
||||||
|
|
||||||
|
library(git2r)
|
||||||
|
library(lubridate)
|
||||||
|
git2r::commit(all=TRUE, message=paste(commit_message,now()))
|
||||||
|
|
||||||
|
system("/usr/bin/git push origin HEAD:refs/heads/main")
|
||||||
|
Loading…
Reference in New Issue
Block a user