Skip to content

Commit

Permalink
Fixed date import bug caused by new CPRD date formats
Browse files Browse the repository at this point in the history
  • Loading branch information
DASpringate committed Oct 15, 2015
1 parent 2616b0a commit f6fb9f1
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 35 deletions.
7 changes: 4 additions & 3 deletions R/cprd_import.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,17 @@ add_to_database <- function(db, files, table_name, dateformat = "%d/%m/%Y", yob_
for(f in files){
if(str_detect(f, "zip$")){
message(sprintf("Unzipping %s...", f), appendLF = FALSE)
dat <- read_zip(f)
dat <- read_zip(f, stringsAsFactors = FALSE)
} else {
message(sprintf("Reading %s...", f), appendLF = FALSE)
dat <- read.delim(f)
dat <- read.delim(f, stringsAsFactors = FALSE)
}
f_dates <- intersect(names(dat), date_fields)
if(length(f_dates)){
message(" Converting date formats...", appendLF = FALSE)
for(column in f_dates){
dat[[column]] <- as.character(as.Date(dat[[column]], format = dateformat))
dat[[column]] <- as.character(as.Date(as.character(dat[[column]]),
format = dateformat))
}
}
if("yob" %in% names(dat)) dat$yob <- dat$yob + yob_origin
Expand Down
Loading

0 comments on commit f6fb9f1

Please sign in to comment.