update ship2plat.R
replace line 143 with:
sdata<-icoads.utils::read_trackmonth(paste0(config$output_dir,"MFILES_TMP"),syr=iyear)
Next change alters nrow(nonship)==0 {next} to >0 and if, else
replace lines 332-346 with:
# manual exclusions
man.ex<-c("ISW1","3FNX","C7M","C7C")
dck.excl<-c(667)
nonship<-subset(nonship,!(id %in% man.ex))
nonship<-subset(nonship,!(grepl("^[0-9]{4,5}$",nonship$id) & dck == 927) )
nonship<-subset(nonship,!(dck %in% dck.excl))
if ( length(uid.want) > 0 ) {
toadd<-subset(sdata,uid %in% uid.want)
cat('adding',nrow(toadd),'reports with generic ID',"\n")
if ( nrow(toadd) > 0 ) {
print(table(toadd$id,toadd$dck,useNA='ifany'))
}
nonship<-rbind(nonship,toadd)
}
After line 383 add:
# and write out ship-only subset
if(!is.null(nonship)) sdata <- subset(sdata,!(uid %in% nonship$uid))
sdata$nonship.flag<-NULL
cat("final ship subset",nrow(sdata),"reports","\n")
if (!dir.exists(paste0(config$output_dir,"MFILES_SHIP"))) dir.create(paste0(config$output_dir,"MFILES_SHIP"))
YRMO <- split(sdata, data.frame(sdata$yr, sdata$mo), drop=TRUE)
names_mo <- gsub("\\.","_", names(YRMO))
names_mo <- gsub("_R",".R", names_mo)
filenames <- paste(paste0(config$output_dir,"MFILES_SHIP/"), names_mo, ".Rda",sep="")
jj<-mapply(saveRDS, YRMO, file = filenames)
# and remove files from MFILES_TMP
flist<-list.files(paste0(config$output_dir,"MFILES_TMP"),pattern=as.character(iyear),full.names=T)
if(length(flist)>0) file.remove(flist)