Skip to content

Expand strings_as_factors_linter() to include as.data.frame() and rbind.data.frame()? #1707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
IndrajeetPatil opened this issue Oct 14, 2022 · 5 comments

Comments

@IndrajeetPatil
Copy link
Collaborator

Since the same concerns apply to these functions as data.frame().

@AshesITR
Copy link
Collaborator

as.data.frame() seems like a good idea, I've never seen rbind.data.frame() called directly in the wild though.

@MichaelChirico
Copy link
Collaborator

we have rbind.data.frame() as an undesirable function IINM. technically it's exported so some users not understanding S3 dispatch may find it and call it directly.

I'd prefer not to encourage that, so I'd limit the extension to as.data.frame().

OTOH, the as.data.frame generic doesnt have stringsAsFactors as an argument, so I worry that will cause false positives.

BTW, could you give some examples where we could detect statically that stringsAsFactors should be included explicitly?

@IndrajeetPatil
Copy link
Collaborator Author

we have rbind.data.frame() as an undesirable function IINM

names(lintr::all_undesirable_functions)
#>  [1] ".libPaths"     "attach"        "browser"       "debug"        
#>  [5] "debugcall"     "debugonce"     "detach"        "ifelse"       
#>  [9] "library"       "loadNamespace" "mapply"        "options"      
#> [13] "par"           "require"       "sapply"        "setwd"        
#> [17] "sink"          "source"        "substring"     "Sys.setenv"   
#> [21] "Sys.setlocale" "trace"         "undebug"       "untrace"

Created on 2022-10-15 with reprex v2.0.2

technically it's exported so some users not understanding S3 dispatch may find it and call it directly.

I've done this in the past 😭

BTW, could you give some examples where we could detect statically that stringsAsFactors should be included explicitly?

For example-

formals(as.data.frame.matrix)
#> $x
#> 
#> 
#> $row.names
#> NULL
#> 
#> $optional
#> [1] FALSE
#> 
#> $make.names
#> [1] TRUE
#> 
#> $...
#> 
#> 
#> $stringsAsFactors
#> [1] FALSE

as.data.frame(matrix("x"))
#>   V1
#> 1  x

Created on 2022-10-15 with reprex v2.0.2

@IndrajeetPatil IndrajeetPatil added the feature a feature request or enhancement label Oct 15, 2022
@MichaelChirico
Copy link
Collaborator

formals(as.data.frame.matrix)

formals(as.data.frame) does not share that parameter.

so the lint logic would have to consist of not just finding as.data.frame calls, but calls like as.data.frame(matrix(.)), as.data.frame(foo(.)), etc. it seems like a combinatorial explosion, and also not likely to catch all that much either TBH.

so I think: don't implement / out of scope

@IndrajeetPatil IndrajeetPatil added out-of-scope and removed feature a feature request or enhancement labels Oct 15, 2022
@IndrajeetPatil
Copy link
Collaborator Author

it seems like a combinatorial explosion, and also not likely to catch all that much either TBH

Fair enough.

@IndrajeetPatil IndrajeetPatil closed this as not planned Won't fix, can't repro, duplicate, stale Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants