# Unknown or uninitialised column

The code below throws the following error (a different number of times on each run, oddly enough, and even before the function has been run on other commands):

Unknown or uninitialised column: `f`.
Unknown or uninitialised column: `L`.

I did not write this code, it was pulled from an instructor's site and is not related to any homework. To me, it looks like all the variables are initialized. What am I missing here?

##ROC FUNCTION

``````#' ROC curve code
#'
#' Based on algo 1 page 866, Fawcett2005
#'
#' @param L observations
#' @param f, predicted prob.
#'
#' @return points in ROC space and score
get_roc <- function(L, f) {
# Calculate P and N
P <- sum(L==1)
N <- sum(L==0)
# Order the observations by prediction
df  <- tibble(L, f)
df <- df %>% arrange(desc(f))
# Set TP and FP to zero
TP <- 0
FP <- 0
# Set up matrix for results
R <- NULL
# Set previous f
f_prev <- -Inf
# set counter
i <- 1
while(i <= length(df\$L)){
if( df\$f[i] != f_prev){
R <- rbind(R, c(FP/N, TP/P, df\$f[i]))
f_prev <- df\$f[i]
}
if(df\$L[i] == 1){
TP <- TP + 1
} else {
FP <- FP + 1
}
i <- i + 1
}
R <- rbind(R, c(FP/N, TP/P, f_prev))
R <- data.frame(R)
colnames(R) <- c("FPR","TPR", "Score")
return(R)
}
``````
``````ROC <- get_roc(L = df\$y, f = df\$predictions)
``````

I'm going to go out on a limb and say this is package version related.
what do you get for

``````sessionInfo()?
``````

The key packages would be

``````other attached packages:
[1] dplyr_1.0.2  tibble_3.0.4
``````

if you have older versions, that may explain your problem.

Hey,

Here is the session info:

R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

Random number generation:
RNG: Mersenne-Twister
Normal: Inversion
Sample: Rounding

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] tibble_3.0.4 titanic_0.1.0 ggplot2_3.3.2 tidyr_1.1.2 dplyr_1.0.2 sparklyr_1.5.1

loaded via a namespace (and not attached):
[1] pillar_1.4.7 compiler_4.0.3 RColorBrewer_1.1-2 dbplyr_2.0.0 r2d3_0.2.3 base64enc_0.1-3
[7] tools_4.0.3 uuid_0.1-4 digest_0.6.27 gtable_0.3.0 jsonlite_1.7.1 evaluate_0.14
[13] lifecycle_0.2.0 pkgconfig_2.0.3 rlang_0.4.9 cli_2.2.0 DBI_1.1.0 rstudioapi_0.13
[19] yaml_2.2.1 parallel_4.0.3 xfun_0.19 withr_2.3.0 httr_1.4.2 knitr_1.30
[25] askpass_1.1 generics_0.1.0 vctrs_0.3.5 htmlwidgets_1.5.2 rappdirs_0.3.1 grid_4.0.3
[31] rprojroot_2.0.2 tidyselect_1.1.0 glue_1.4.2 forge_0.2.0 R6_2.5.0 fansi_0.4.1
[37] rmarkdown_2.5 blob_1.2.1 purrr_0.3.4 magrittr_2.0.1 scales_1.1.1 ellipsis_0.3.1
[43] htmltools_0.5.0 MASS_7.3-53 assertthat_0.2.1 colorspace_2.0-0 config_0.3 utf8_1.1.4
[49] tinytex_0.27 munsell_0.5.0 openssl_1.4.3 crayon_1.3.4

Before I did not have the tibble package loaded for sure. I loaded it and now in addition to the errors mentioned above I get the following error:

Error: arrange() failed at implicit mutate() step. x Could not create a temporary column for `..1`. i `..1` is `f`.

This may be too simple, but have you tried Ctrl+Shift+F10 restarting your R session ?

It was worth a shot, but the same errors were still returned, except for the error with the arrange function. I fixed this. It was due to a missing object in the function call. Restarting and changing things so many times makes it easy to forget to run a segment every now and then.

Is there a way to see which code line is causing the warnings? This may help.

I know I am not the only one with this problem: Persistent "Unknown or uninitialised column" warnings

If a reproducible example is needed, this one should do it. Maybe I should tag it as a bug?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.