R/write_first_lookup.R

Defines functions write_first_lookup

Documented in write_first_lookup

#' Write the first lookup file For a new vocabulary  to query for mapping
#' @param path_to_catalogue_dir path to the directory in the biblio-tech catalogue for the new vocabulary
#' @param vocabulary_prefix prefixes for this vocabulary used for the SQL_KEYWORD_ID and SQL_KEYWORD fields
#' @importFrom readr write_csv
#' @export
#' 
write_first_lookup <-
        function(path_to_catalogue_dir, vocabulary_prefix) {
                path_to_lookup <- paste0(path_to_catalogue_dir, "/LOOKUP.csv")
                
                if (!file.exists(path_to_lookup)) {
                        prefixed_columns <- c("SQL_KEYWORD_TIMESTAMP",
                                              "SQL_KEYWORD_ID",
                                              "SQL_KEYWORD")
                        colnames_a <- paste0(toupper(vocabulary_prefix), "_", prefixed_columns)
                        colnames_b <- c("COORDINATE_CUI",
                                        "COORDINATE_STR",
                                        "NET_CUI_COUNT",
                                        "NET_ROW_COUNT")
                        
                        all_colnames <- c(colnames_a,
                                          colnames_b)
                        
                        x <- data.frame(matrix(ncol = length(all_colnames)))
                        colnames(x) <- all_colnames
                        
                        x <- x[-1,]
                        
                        readr::write_csv(x, path = paste0(path_to_catalogue_dir, "/LOOKUP.csv"))
                }
        }
patelm9/cartographR2 documentation built on Dec. 24, 2019, 3:03 p.m.