Blame view

ISO27001effectiveness/R/Hackmageddon_Parser.R 1.23 KB
Imanol-Mikel Barba Sabariego authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#------------------------------------------------------------------------------------------------------
#-----------------------------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]")
  }
}

#-----------------------------

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
}

ParseHMFolder <- function(folder){
  filelist <- list.files(folder)
  frames <- lapply(paste(folder,filelist,sep=""),ParseHMExcel)
  merged_frame =  merge(frames)
  merged_frame
}