R/pisa_2018_info.R

Defines functions pisa_2018_students

# # TODO Refactor this
# #'
# #'
# #' @export
# pisa_2018_check <- function(data, path, file) {
#     path_rdata <- ("data/raw/pisa_2018.Rdata")
#     exists_rdata <- exists_pisa2018_rdata(path_rdata)
#     if (!(exists_rdata)) {
#         student_pisa_2018 <- student_pisa_2018(path, file)
#         save(student_pisa_2018, file = path_rdata)
#         return(student_pisa_2018)
#     }
#     tryCatch()
#     # x <- cgwtools::lsdata(path_rdata)
#     if (data == "student") {
#         load(path_rdata)
#         return(student_pisa_2018)
#     }
# }

pisa_2018_students <- function(path_rdata) {
    load(path_rdata)
    return(pisa_2018_students)
}

# # TODO Maybe delete
# exists_pisa2018_rdata <- function(path_rdata) {
#     file_test("-f", path_rdata)
# }

# # TODO reduce
# student_pisa_2018 <- function(path, file) {
#     path_file <- paste0(path, file)
#     exists_student_path <- file_test("-f", path_file)
#     if (exists_student_path) {
#         data <- foreign::read.spss(path_file, to.data.frame = TRUE)
#     } else {
#         options(warn = -1)
#         # Dowload file for OECD web
#         url <- "https://webfs.oecd.org/pisa2018/SPSS_STU_QQQ.zip"
#         file <- "STU/CY07_MSU_STU_QQQ.sav"
#         temp <- tempfile()
#         download.file(url, temp)
#         file <- unzip(temp, file)
#         file_dir <- dirname(file)
#         data <- foreign::read.spss(file, to.data.frame = TRUE)
#         base::unlink(temp, recursive = TRUE)
#         base::unlink(file_dir, recursive = TRUE)
#         options(warn = 0)
#         rm(
#             url,
#             temp
#         )
#     }
#     return(data)
# }
Lykansito/RPisaStats documentation built on Oct. 7, 2020, 2:30 a.m.