other_Code/11_createTestData.R

library(eatGADS)

# simple DB data set for testing
# ------------------------------------------------------------------------------------------------------------------
df1 <- df2 <- list()
df1$dat <- data.frame(v1 = 1,
                      ID2 = 1)

df2$dat <- data.frame(ID2 = 1:1,
                      v2 = 1:2)

df1$labels <- data.frame(varName = c("v1"),
                         varLabel = c("var 1"),
                         value = c(NA),
                         label = c(NA),
                         missings = c(NA),
                         stringsAsFactors = FALSE)

df2$labels <- data.frame(varName = c("ID2", "v2"),
                         varLabel = c("ID var", "var 2"),
                         value = c(-99, 1),
                         label = c("NA", "One"),
                         missings = c("miss", NA),
                         stringsAsFactors = FALSE)

pkList <- list(df1 = "v1",
               df2 = c("ID2", "v2"))
fkList <- list(df1 = list(References = NULL, Keys = NULL),
               df2 = list(References = "df1", Keys = "ID2"))

expected_labels <- data.frame(varName = c("v1", "ID2", "v2"),
                                               varLabel = c("var 1", "ID var", "var 2"),
                                               value = c(NA, -99, 1),
                                               label = c(NA, "NA", "One"),
                                               missings = c(NA, "miss", NA),
                                               data_table = c(rep("df1", 1), rep("df2", 2)), stringsAsFactors = FALSE)

expected_bigList <- list(dfList = list(df1 = df1$dat, df2 = df2$dat),
                         labelList = expected_labels)


save(df1, df2, pkList, fkList, expected_labels, expected_bigList,
     file = "c:/Benjamin_Becker/02_Repositories/packages/eatGADS/tests/testthat/helper_dbdata.rda")

# create corresponding data base
bigList <- mergeLabels(df1 = df1, df2 = df2)
allList <- addKeys(bigList, pkList = pkList, fkList = fkList)

# remove database before
createDB(allList, filePath = "c:/Benjamin_Becker/02_Repositories/packages/eatGADS/tests/testthat/helper_dataBase.db")







# data set included as example data set in package
# ------------------------------------------------------------------------------------------------------------------

# tbd!!!

student <- teach <- list()
student$datList <- data.frame(IDSTUD = 1:4,
                       Mig = c(1, 2, 1, 2),
                       IDTEACH = c(1, 1, 2, 2))

teach$datList <- data.frame(IDTEACH = c(1:2, 1:2),
                     subject = c(rep(1, 2), rep(2, 2)),
                     stringsAsFactors = FALSE)

student$labelList <- data.frame(varName = c("IDSTUD", "subject", "subject"),
                                varLabel = c("ID teacher", "math", "engl"),
                                value = c(NA, 1, 2),
                                label = c(NA, "Mig", "No Mig"),
                                missings = c(NA, NA, NA),
                                stringsAsFactors = FALSE)

teach$labelList <- data.frame(varName = c("IDTEACH", "subject", "subject"),
                              varLabel = c("ID teacher", "math", "engl"),
                              value = c(NA, 1, 2),
                              label = c(NA, "Mig", "No Mig"),
                              missings = c(NA, NA, NA),
                              stringsAsFactors = FALSE)



# as list
datList <- list(student = student,
                teach = teach)
pkList <- list(student = "IDSTUD",
               teach = c("IDTEACH", "subject"))
fkList <- list(student = list(References = NULL, Keys = NULL),
               teach = list(References = "student", Keys = c("IDTEACH", "subject")))


# save everything into data folder (in package)
devtools:::use_data(datList, internal=FALSE, overwrite = TRUE)
devtools:::use_data(pkList, internal=FALSE, overwrite = TRUE)
devtools:::use_data(fkList, internal=FALSE, overwrite = TRUE)
b-becker/eatGADS documentation built on May 24, 2019, 8:47 p.m.