collapse icon indicating copy to clipboard operation
collapse copied to clipboard

F() overriding FALSE

Open edrubin opened this issue 5 years ago • 3 comments

First off: Thank you so much for a fantastic package.

I keep running into a problem generated by the F() function: it has overwritten base R's logical vector (for FALSE). Is there any way we give F() a different name? I know there's an issue of backward compatibility, but a lot of my previous code also breaks when collapse::F() masks base::F.

Simple example of the problem

library(data.table, collapse)
# Create a data table
> dt = data.table(var = c(TRUE, FALSE), val = 1:2)
# View data table
> dt
     var val
1:  TRUE   1
2: FALSE   2
# Filter where 'var' is FALSE (shorthand)
> dt[var == F]
Error: comparison (1) is possible only for atomic and list types
# Filter where 'var' is FALSE
> dt[var == FALSE]
     var val
1: FALSE   2

This behavior seems pretty undesirable (especially since T and F are so much quicker to type).

Thanks for considering my issue!

edrubin avatar Nov 04 '21 20:11 edrubin

Hi, thanks, this has come up before. I can think about depreciating F, but I actually wouldn't like that because it's indeed a backward compatibility issue. Th solution to your code is simply creating F <- FALSEin the global environment. In base R Fis simply a variable exported from the base package, just like collapse exports variables like .FAST_STAT_FUN.

SebKrantz avatar Nov 04 '21 21:11 SebKrantz

Totally understand the backwards compatibility issue, but it seems like many more people use F as FALSE than as collapse::F(). Your solution would also work for backwards compatibility issues, e.g., F <- FF.

Either way, thanks for your work on a terrific package—and for your quick reply!

edrubin avatar Nov 04 '21 22:11 edrubin

Thanks, I agree with that. I wouldn't rename F to FFbut simply remove it. On the other hand I don't totally dislike the idea that using collapse would compell some peopel to write more secure code to avoid having to create an additional variable F. I'll keep thinking about it.

SebKrantz avatar Nov 04 '21 22:11 SebKrantz