Comments (1)
I think this may actually be a base R bug. I believe that all data.frames should have a names
attribute. If there are 0 columns then it should be set to character()
. The fact that that isn't the case here is odd.
attributes(as.data.frame(matrix(nrow = 0, ncol = 0)))
#> $class
#> [1] "data.frame"
#>
#> $row.names
#> integer(0)
attributes(data.frame())
#> $names
#> character(0)
#>
#> $row.names
#> integer(0)
#>
#> $class
#> [1] "data.frame"
Not having a names
attribute can seriously break other parts of base R, making my guess that it is a base R bug feel more validated:
# Good OOB error
df <- data.frame()
df[1]
#> Error in `[.data.frame`(df, 1): undefined columns selected
# WTF is this
df <- as.data.frame(matrix(nrow = 0, ncol = 0))
df[1]
#> NULL
#> <0 rows> (or 0-length row.names)
In general dplyr works fine with the 2nd case, i.e. a well formed data frame
I think we should consider switching from names2()
to names()
in DataMask
to try and catch this earlier on:
Line 14 in d698022
i.e. something like
names <- names(data)
if (is.null(names)) {
abort("Can't transform a data frame with `NULL` names.")
}
which would go nicely with our other names related checks there.
It did use names()
in the past, but I switched to names2()
here to supposedly fix this exact case. Supposedly not supporting NULL
column names broke 2 packages and that was what I was out to fix, but that seems like a false alarm because current CRAN dplyr obviously already doesn't support NULL
column names based on this issue. So the change above would just be giving a better error message for this invalid data frame.
#4896
from dplyr.
Related Issues (20)
- A very strange error in an edge case
- Allow .by=row_number() in mutate statements HOT 1
- Relocate multiple columns in a pairwise fashion HOT 2
- Feature Request: Add `continuous` parameter to `slice()` or new `slice_continuous()` HOT 1
- bind_rows unexpectedly renames columns
- Deprecation of one of dplyr features in package "ncappc" HOT 3
- c_across() docs imply a dependency on rowwise()
- Variable scoping issue with .data inside lambda Ffunction used in across() HOT 2
- In `select` `!` and `-` work differently HOT 1
- Weird behavior with bind_rows(), mutate(), and ggeffects package
- rank function not working properly after using mean function HOT 1
- summarize() is not equivalent to summarise() HOT 1
- Segfault when using rbind() to combine two rowwise data frames HOT 3
- A proposed function to port plyr::mapvalues() to dplyr HOT 1
- FR: allow `pick()` to rename in `distinct()` + some thoughts about `arrange()` allowing renaming.
- group_by() documentation (v1.1.4) doesn't indicate whether ... is <tidy-select> or <data-masking> (it's <data-masking>)
- Document minus operator in tidy-select and select HOT 3
- case_when inserting NAs instead of new assigned values despite all levels are included HOT 3
- .onLoad setting options
- Inconsistency in Results Using sum(. != 3) within Pipeline Operations (%>%) dplyr version 1.1.4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dplyr.