@@ -69,16 +69,16 @@ vw <- function(training_data, validation_data, model='mdl.vw',
69
69
# # this should not create an unnecessary copy of the arguments
70
70
data_args = list (train = training_data , val = validation_data )
71
71
path_data_args = list (path_vw_data_train , path_vw_data_val )
72
- for (i in 1 : 2 )
72
+ for (i in seq_along( data_args ) )
73
73
{
74
- if ( " data.frame " %in% class( data_args [[i ]] ))
74
+ if (inherits( data_args [[i ], " data.frame " ))
75
75
{
76
76
if (is.null(target ))
77
77
stop(paste0(names(data_args )[i ],
78
78
" data argument: input argument is a data.frame, argument 'target' should be specified " ))
79
79
80
- if (class (path_data_args [[i ]]) != " character " )
81
- path_data_args [[i ]] = paste0 (tempdir()," / " , names(data_args )[i ]," .vw" )
80
+ if (! is.character (path_data_args [[i ]]))
81
+ path_data_args [[i ]] = file.path (tempdir(),paste0( names(data_args )[i ]," .vw" ) )
82
82
83
83
dt2vw(data = data_args [[i ]], fileName = path_data_args [[i ]],
84
84
namespaces = namespaces , target = target , weight = weight , tag = tag )
@@ -117,29 +117,29 @@ vw <- function(training_data, validation_data, model='mdl.vw',
117
117
118
118
if (is.null(out_probs ))
119
119
{
120
- out_probs = paste0 (tempdir()," / preds.vw" )
121
- del_prob = T
120
+ out_probs = file.path (tempdir()," preds.vw" )
121
+ del_prob = TRUE
122
122
}
123
123
else
124
- del_prob = F
124
+ del_prob = FALSE
125
125
126
126
validation_data = path_data_args [[2 ]]
127
127
predict = sprintf(' vw -t -i %s -p %s %s -d %s' , model , out_probs , link_function , validation_data )
128
128
system(predict )
129
129
130
130
if (do_evaluation ){
131
- if (" data.frame " %in% class (data_args [[2 ]]))
131
+ if (inherits (data_args [[2 ]], " data.frame " ))
132
132
{
133
133
if (is.null(validation_labels ))
134
134
{
135
- del_val = T
136
- validation_labels = paste0 (tempdir()," / val_labs.vw" )
135
+ del_val = TRUE
136
+ validation_labels = file.path (tempdir()," val_labs.vw" )
137
137
}
138
138
else
139
- del_val = F
139
+ del_val = FALSE
140
140
141
- write.table(x = data_args [[2 ]][[target ]], file = validation_labels , row.names = F ,
142
- col.names = F )
141
+ write.table(x = data_args [[2 ]][[target ]], file = validation_labels , row.names = FALSE ,
142
+ col.names = FALSE )
143
143
}
144
144
145
145
if (use_perf ){
@@ -151,7 +151,7 @@ vw <- function(training_data, validation_data, model='mdl.vw',
151
151
}
152
152
}
153
153
154
- if (verbose & do_evaluation ){
154
+ if (verbose && do_evaluation ){
155
155
cat(' Model Parameters\n ' )
156
156
cat(cmd )
157
157
verbose_log = sprintf(' AUC: %s' , auc )
@@ -162,8 +162,8 @@ vw <- function(training_data, validation_data, model='mdl.vw',
162
162
probs = fread(out_probs )[[' V1' ]]
163
163
164
164
# # delete temporary files
165
- for (i in 1 : 2 )
166
- if (" data.frame " %in% class (data_args [[i ]]))
165
+ for (i in seq_along( data_args ) )
166
+ if (inherits (data_args [[i ]], " data.frame " ))
167
167
file.remove(path_data_args [[i ]])
168
168
if (del_prob )
169
169
file.remove(out_probs )
@@ -184,8 +184,8 @@ roc_auc <- function(out_probs, validation_labels, plot_roc, cmd, ...){
184
184
stop(' The length of the probabilities and labels is different' )
185
185
186
186
# Fix cmd for adding it in title
187
- cmd = sapply (strsplit(cmd , ' -f' ), function (x ) paste0(x , collapse = ' \n ' ))
188
- cmd = sapply (strsplit(cmd , ' -c' ), function (x ) paste0(x , collapse = ' \n ' ))
187
+ cmd = vapply (strsplit(cmd , ' -f' ), function (x ) paste0(x , collapse = ' \n ' ), character ( 1 ))
188
+ cmd = vapply (strsplit(cmd , ' -c' ), function (x ) paste0(x , collapse = ' \n ' ), character ( 1 ))
189
189
190
190
# Plot ROC curve and return AUC
191
191
roc = roc(labels , probs , auc = TRUE , print.auc = TRUE , print.thres = TRUE )
0 commit comments