Integrating a Loop Around My Function for Testing

Here's the basic scaffolding of what a potential for loop solution could look like:

x <- data.frame(MonthsEmployed = 1:3,
                MonthlyRent = 1:3,
                CO_Age = 1:3,
                LN_ialenofres = 1:3,
                NewVehInd = logical(3))

results <- numeric(length = nrow(x))

for (i in seq_len(nrow(x))) {
  results[i] <- run(calculate_fnscore, list("MonthsEmployed" = x$MonthsEmployed[i],
                                  "MonthlyRent" = x$MonthlyRent[i],
                                  "CO_Age" = x$CO_Age[i],
                                  "LN_ialenofres" = x$LN_ialenofres[i],
                                  "NewVehInd" = x$NewVehInd[i]))
}

A few questions:

  1. Where are the functions run, calculate_fnscore, and boolean_to_bit coming from? Did you write these or are they from a package? I assume that the list contains arguments to the function calculate_fnscore, and I'm unsure of the advantage of passing these via run.
  2. Does your CSV file use NULL for missing values? If yes, you could convert these to NA by setting the argument na.strings = "NULL" for the function read.csv.
  3. Would it be possible to convert your question to a reproducible example?
2 Likes