Commit 0becaf7f authored by Heraut Louis's avatar Heraut Louis
Browse files

Taking into account of missing file

parent abaf448d
No related merge requests found
Showing with 56 additions and 40 deletions
+56 -40
......@@ -178,29 +178,37 @@ extract_info = function (computer_data_path, filedir, filename, verbose=TRUE) {
# Get the file path to the data
file_path = file.path(computer_data_path, filedir, filename)
# Extract all the header
infotxt = c(readLines(file_path, n=41))
# Create a tibble with all the information needed
df_info =
tibble(code=trimws(substr(infotxt[11], 38, nchar(infotxt[11]))),
nom=trimws(substr(infotxt[12], 39, nchar(infotxt[12]))),
territoire=trimws(substr(infotxt[13], 39, nchar(infotxt[13]))),
L93X=as.numeric(substr(infotxt[16], 38, 50)),
L93Y=as.numeric(substr(infotxt[16], 52, 63)),
surface=as.numeric(substr(infotxt[19], 38, 50)),
statut=iStatut[trimws(substr(infotxt[26], 38, 50))],
finalite=iFinalite[trimws(substr(infotxt[26], 52, 56))],
type=iType[trimws(substr(infotxt[26], 58, 58))],
influence=iInfluence[trimws(substr(infotxt[26], 60, 60))],
debit=iDebit[trimws(substr(infotxt[26], 62, 62))],
QBE=iQBE[trimws(substr(infotxt[26], 72, 72))],
QME=iQME[trimws(substr(infotxt[26], 74, 74))],
QHE=iQHE[trimws(substr(infotxt[26], 76, 76))],
file_path=file_path
)
return (df_info)
if (file.exists(file_path)) {
# Extract all the header
infotxt = c(readLines(file_path, n=41))
# Create a tibble with all the information needed
df_info =
tibble(code=trimws(substr(infotxt[11], 38, nchar(infotxt[11]))),
nom=trimws(substr(infotxt[12], 39, nchar(infotxt[12]))),
territoire=trimws(substr(infotxt[13], 39, nchar(infotxt[13]))),
L93X=as.numeric(substr(infotxt[16], 38, 50)),
L93Y=as.numeric(substr(infotxt[16], 52, 63)),
surface=as.numeric(substr(infotxt[19], 38, 50)),
statut=iStatut[trimws(substr(infotxt[26], 38, 50))],
finalite=iFinalite[trimws(substr(infotxt[26], 52, 56))],
type=iType[trimws(substr(infotxt[26], 58, 58))],
influence=iInfluence[trimws(substr(infotxt[26], 60, 60))],
debit=iDebit[trimws(substr(infotxt[26], 62, 62))],
QBE=iQBE[trimws(substr(infotxt[26], 72, 72))],
QME=iQME[trimws(substr(infotxt[26], 74, 74))],
QHE=iQHE[trimws(substr(infotxt[26], 76, 76))],
file_path=file_path
)
return (df_info)
} else {
print(paste('filename', file_path, 'do not exist'))
return (NULL)
}
}
# Example
......@@ -270,24 +278,31 @@ extract_data = function (computer_data_path, filedir, filename, verbose=TRUE) {
# Get the file path to the data
file_path = file.path(computer_data_path, filedir, filename)
# Extract the data as a data frame
df_data = read.table(file_path,
header=TRUE,
na.strings=c(' -99', ' -99.000'),
sep=';',
skip=41)[,1:2]
# Extract all the information for the station
df_info = extract_info(computer_data_path, filedir, filename, verbose=FALSE)
# Get the code of the station
code = df_info$code
# Create a tibble with the date as Date class and the code of the station
df_data = tibble(Date=as.Date(as.character(df_data$Date),
format="%Y%m%d"),
df_data[-1],
code=code)
return (df_data)
if (file.exists(file_path)) {
# Extract the data as a data frame
df_data = read.table(file_path,
header=TRUE,
na.strings=c(' -99', ' -99.000'),
sep=';',
skip=41)[,1:2]
# Extract all the information for the station
df_info = extract_info(computer_data_path, filedir, filename, verbose=FALSE)
# Get the code of the station
code = df_info$code
# Create a tibble with the date as Date class and the code of the station
df_data = tibble(Date=as.Date(as.character(df_data$Date),
format="%Y%m%d"),
df_data[-1],
code=code)
return (df_data)
} else {
print(paste('filename', file_path, 'do not exist'))
return (NULL)
}
}
# Example
......
......@@ -4,6 +4,7 @@ install.packages("tools")
install.packages("devtools")
install.packages("dplyr")
install.packages("ggplot2")
install.packages("officer")
library(devtools)
install_github("https://github.com/benRenard/BFunk")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment