@@ -69,16 +69,16 @@ vw <- function(training_data, validation_data, model='mdl.vw',
6969 # # this should not create an unnecessary copy of the arguments
7070 data_args = list (train = training_data , val = validation_data )
7171 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 ) )
7373 {
74- if ( " data.frame " %in% class( data_args [[i ]] ))
74+ if (inherits( data_args [[i ], " data.frame " ))
7575 {
7676 if (is.null(target ))
7777 stop(paste0(names(data_args )[i ],
7878 " data argument: input argument is a data.frame, argument 'target' should be specified " ))
7979
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" ) )
8282
8383 dt2vw(data = data_args [[i ]], fileName = path_data_args [[i ]],
8484 namespaces = namespaces , target = target , weight = weight , tag = tag )
@@ -117,29 +117,29 @@ vw <- function(training_data, validation_data, model='mdl.vw',
117117
118118 if (is.null(out_probs ))
119119 {
120- out_probs = paste0 (tempdir()," / preds.vw" )
121- del_prob = T
120+ out_probs = file.path (tempdir()," preds.vw" )
121+ del_prob = TRUE
122122 }
123123 else
124- del_prob = F
124+ del_prob = FALSE
125125
126126 validation_data = path_data_args [[2 ]]
127127 predict = sprintf(' vw -t -i %s -p %s %s -d %s' , model , out_probs , link_function , validation_data )
128128 system(predict )
129129
130130 if (do_evaluation ){
131- if (" data.frame " %in% class (data_args [[2 ]]))
131+ if (inherits (data_args [[2 ]], " data.frame " ))
132132 {
133133 if (is.null(validation_labels ))
134134 {
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" )
137137 }
138138 else
139- del_val = F
139+ del_val = FALSE
140140
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 )
143143 }
144144
145145 if (use_perf ){
@@ -151,7 +151,7 @@ vw <- function(training_data, validation_data, model='mdl.vw',
151151 }
152152 }
153153
154- if (verbose & do_evaluation ){
154+ if (verbose && do_evaluation ){
155155 cat(' Model Parameters\n ' )
156156 cat(cmd )
157157 verbose_log = sprintf(' AUC: %s' , auc )
@@ -162,8 +162,8 @@ vw <- function(training_data, validation_data, model='mdl.vw',
162162 probs = fread(out_probs )[[' V1' ]]
163163
164164 # # 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 " ))
167167 file.remove(path_data_args [[i ]])
168168 if (del_prob )
169169 file.remove(out_probs )
@@ -184,8 +184,8 @@ roc_auc <- function(out_probs, validation_labels, plot_roc, cmd, ...){
184184 stop(' The length of the probabilities and labels is different' )
185185
186186 # 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 ))
189189
190190 # Plot ROC curve and return AUC
191191 roc = roc(labels , probs , auc = TRUE , print.auc = TRUE , print.thres = TRUE )
0 commit comments