nuclearWeaponStates data.frame
This document describes how to add new information to the
nuclearWeaponStates
dataset in the Ecdat
package.
The first step is to update the companion
nuclearWeaponStates.Rd
help file.
Then update the nuclearWeaponStates
object so it matches
the revised description.
One way to do this is to export the nuclearWeaponStates
dataset as a csv file so you can edit it in a spreadsheet:
library(Ecdat)
availInPkg <- objects(2,
pattern='nuclearWeaponStates')
canWrite <- FALSE
(TempDir <- tempdir())
## [1] "/tmp/RtmpMb0UTZ"
# Write the name of TempDir so I can find it.
# Or set
# TempDir <- getwd()
# for manual processing.
if('nuclearWeaponStates' %in% availInPkg){
data(nuclearWeaponStates)
TempFile <- file.path(TempDir,
'nuclearWeaponStates.csv')
canWr <- try(write.csv(nuclearWeaponStates,
TempFile, row.names=FALSE))
if(!inherits(canWr, 'try-error')){
canWrite <- TRUE
}
}
getwd()
## [1] "/tmp/RtmpKx4vG5/Rbuild21a72e8a80b5/Ecfun/vignettes"
## character(0)
If desired, edit the csv file just created as mentioned above. Ignore
firstTestYr
and yearsSinceLastFirstTest
,
because we compute them in this vignette from firstTest
.
That’s because we want (a) firstTestYr
to be
firstTest
as numeric years rather than as days since
1970-01-01, and (b) yearsSinceLastFirstTest
to be
diff(firstTestYr)
.
If you edit it externally, put it in the current working directory and read it as follows:
library(Ecfun)
if(canWrite){
nWS <- read.csv(TempFile,
stringsAsFactors = FALSE)
igno <- c('nation', 'ctry', 'Maddison')
igno. <- (igno %in% names(nWS))
Dts <- c("firstTest", "startNucPgm")
Dts. <- (Dts %in% names(nWS))
nWSdf <-asNumericDF(nWS,
ignore=igno[igno.], Dates=Dts[Dts.])
}
(The “ignore” argument in asNumericDF
forces that function to retain the data in those columns as is. In this
case, they should be of class “character”. Similarly, the “Dates”
argument converts the indicated column to class “Date”.)
firstTestYr
and
yearsSinceLastFirstTest
if(canWrite){
nmsNucWeapSt <- names(nWSdf)
if('firstTest' %in% nmsNucWeapSt){
firstTestYr <- lubridate::decimal_date(
nWSdf$firstTest)
yearsSinceLastFirstTest <- c(NA,
diff(firstTestYr) )
} else {
print(nmsNucWeapSt)
err <- paste("'firstTest' not in",
"names(nuclearWeaponStates)")
stop(err)
}
nuclearWeaponStates <- nWSdf
nuclearWeaponStates$firstTestYr <- firstTestYr
if('startNucPgm' %in% nmsNucWeapSt){
startNucPgmYr <- lubridate::decimal_date(
nWSdf$startNucPgm)
nuclearWeaponStates$startNucPgmYr <- startNucPgmYr
}
# else {
# print(nmsNucWeapSt)
# err2 <- paste("'startNucPgm' not in",
# "names(nuclearWeaponStates)")
# stop(err2)
# }
}
nuclearWeapons
Check the number of nuclearWeapons