Search code examples
rrattle

Rattle loads titanic_train full data but fails when subsetted


I can load the titanic_train dataset into Rattle with no problem, but if I subset a few columns I get the error:

Error in paste(., collapse=""): cannot coerce type 'closure' to vector of type 'character'

Here's my work flow:

library(magrittr)
library(rattle)
library(titanic)
library(dplyr)

dat <- titanic_train
df <- dat[c(2, 3, 5, 6)]
df %<>% mutate_at(c("Survived", "Sex"), factor)
rattle()

Both dat and df show up as class data.frame.

Rattle loads dat correctly, but fails with the error code when I try to load df.

What am I missing?

Update

Now I'm more confused. The following code works with the dat2 data frame, but I get the error when trying to load df in Rattle as an R Dataset. (I updated mutate_at to mutate(across but it made no difference.

library(titanic)
library(magrittr)
library(rattle)
library(dplyr)

dat <- titanic_train

dat2 <- dat[c(2,3,5,6)]
df <- dat[c(2,3,5,6)]

dat2 %<>% mutate(across(c("Survived","Sex"), factor))
df %<>% mutate(across(c("Survived","Sex"), factor))

rattle()

Solution

  • The problem seems to be that Rattle is seeing the df object as the stats package call to the df function for the F distribution. The same error occurs when naming the object dt in the code above -- Rattle fails because (I think) it considers dt the T distribution function. Changing the object name to dt1 or df1 works just fine in Rattle.

    This wasn't noticeable when I tried class(df) or typeof(df). While it's dangerous to name objects with existing function/object names, df for data frame and dt for data table are commonly seen.