ISOSurvey_Parser.R 1.88 KB
#------------------------------------------------------------------------------------------------------
#-----------------------------Parser Excel - ISO survey------------------------------------------------
#------------------------------------------------------------------------------------------------------



#-----------------------------Library tests / install--------------------------------------------------


#' Install and load required libraries
#'
#' This function checks if every required library is installed to be loaded, if not they will be installed and then loaded.
#' Libraries installed:
#'  xlsx to parse excel files like ISO survey source format
LoadParserLibraries <- function(){
  if (!require("xlsx"))
  {
    install.packages("xlsx")
    if (!require("xlsx")) stop("Error while loading package [xlsx]")
  }
}

#-----------------------------Read from file-----------------------------------------------------------

#' Get data frame from an excel file
#'
#' Check if the file exists and then parse it into a data.frame
#' @param file path to excel file
#' @param sheet index of sheet to parse
#'
#' @return data.frame
ParseExcelFileRaw <- function(file, sheet){

  if (!file.exists(file)) {
    stop(paste("Error, file [", file, "] not found"))
  }

  dataset <- read.xlsx2(file, sheet, header = TRUE)

  dataset
}

#' Process raw data from ISO survey
#'
#' ...
#' @param dataset.raw raw data from ISO Survey excel file
#'
#' @return data.frame
ProccesISOSurveyRaw <- function(dataset.raw){
#Complete
}

#ISO_survey_certificates_countries <- read.xlsx2(paste(getwd(), "/Data/ISO/iso_27001_iso_survey2015_preprocessed.xlsx", sep = ""), 1)
#ISO_survey_sites_countries <- read.xlsx2(paste(getwd(), "/Data/ISO/iso_27001_iso_survey2015_preprocessed.xlsx", sep = ""), 2)
#ISO_survey_certificates_sector <- read.xlsx2(paste(getwd(), "/Data/ISO/iso_27001_iso_survey2015_preprocessed.xlsx", sep = ""), 3)