forked from EOGrady21/ODF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathodfedit.R
84 lines (77 loc) · 2.09 KB
/
odfedit.R
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
####Edit ODF####
#' Edit an ODF attribute
#'
#' @param odffile an ODF file connection
#' @param param The parameter you wish to edit
#' @param value The value you wish to insert into the odf file
#'
#' @return an updated ODF file
#' @export
#'
#' @examples
#'
#' editParam('MADCPS*...*.ODF, 'MIN_DEPTH', '2.5')
editParam <- function(odffile, param, value){
o <- read_odf(odffile)
headindex <- grep(param, o)
header <- names(o[headindex])
eval(parse(text = paste0('o$', header, '$', param, '<- value')))
write_odf(odf_object = o, output_file = odffile)
}
#' edit an ODF data frame
#'
#' Function returns ODF data frame which can be edited/ processed as necessary then written out again
#'
#' @param odffile an odf file connection
#'
#' @return the data frame from the odf file
#' @export
#'
#' @examples
editData <- function(odffile){
o <- read_odf(odffile)
data <- o$DATA
return (data)
}
#' Batch Edit ODF files
#'
#'This function can be used to edit a series of ODF files at a time, if a batch
#'of ODF files were produced with an incorrect parameter or value
#'
#'
#' @param odffiles a list of odf file names which are to be edited
#' @param param The parameter you wish to edit
#' @param value The value you wish to insert into ODF files
#'
#' @return edited ODF files
#' @export
#'
#' @examples see editParam example
#'
#' batchedit(odffiles = list.files(path = '.', pattern = '*.ODF'), param = 'ORGANIZATION', value = 'DFO SABS')
#'
#'
batchedit <- function(odffiles, param, value){
for ( i in 1:length(odffiles)){
o <- read_odf(odffiles[i])
headindex <- grep(param, o)
header <- names(o[headindex])
eval(parse(text = paste0('o$', header, '$', param, '<- ', value)))
write_odf(odf_object = o, output_file = odffiles[i])
}
}
#' odfSetMetadata
#'
#' @param odffile ODF file connection
#' @param param parameter of metadata to be changed
#' @param value new value of metadata parameter
#'
#' @return an oce odf object
#' @export
#'
#' @examples
odfSetMetadata <- function(odffile, param, value){
odf <- read.odf(odffile)
odf <- oceSetMetadata(odf, param, value)
return(odf)
}