From 274ef06d96e9235374c7338a7552305f6388c029 Mon Sep 17 00:00:00 2001 From: Miguel Tuñón Date: Sat, 17 Dec 2016 22:34:31 +0100 Subject: [PATCH] Changed [Hackmaggedon_Parser.R], added [ProccessHMRaw] to remove NAs and changed [PArseHMFolder] because of problems with lapply --- ISO27001effectiveness/R/Hackmageddon_Parser.R | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/ISO27001effectiveness/R/Hackmageddon_Parser.R b/ISO27001effectiveness/R/Hackmageddon_Parser.R index 176c764..8cf1d21 100644 --- a/ISO27001effectiveness/R/Hackmageddon_Parser.R +++ b/ISO27001effectiveness/R/Hackmageddon_Parser.R @@ -4,38 +4,33 @@ -#-----------------------------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]") - } -} - -#----------------------------- - ParseHMExcel <- function(file){ print(file) if (!file.exists(file)) { stop(paste("Error, file [", file, "] not found")) } - dataset <- read.xlsx2(file, 1, header = TRUE,colIndex = 2:10) + dataset <- read.xlsx2(file, 1, header = TRUE,colIndex = 2:10, colClasses = c("Date", "character", "character", "character", "character", "character", "character", "character")) + dataset +} + +ProccesHMRaw <- function(dataset.raw){ + + #Remove rows with Date NA + dataset <- dataset.raw[!is.na(dataset.raw$Date),] + dataset } ParseHMFolder <- function(folder){ filelist <- list.files(folder) - frames <- lapply(paste(folder,filelist,sep=""),ParseHMExcel) - merged_frame = merge(frames) - merged_frame + #frames <- lapply(paste(folder,filelist,sep = ""),ParseHMExcel) + dataset <- ProccesHMRaw(ParseHMExcel(paste(folder,filelist[1],sep = "/"))) + + for (i in 2:length(filelist)) { + dataset <- rbind(dataset, ProccesHMRaw(ParseHMExcel(paste(folder,filelist[i],sep = "/")))) + } + + dataset } -- libgit2 0.22.2