Skip to content
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

Provide a convenient way to silence "New names" message when using col_names = FALSE #580

Closed
wgrundlingh opened this issue Aug 9, 2019 · 11 comments

Comments

@wgrundlingh
Copy link

When using col_names = FALSE, an automated message with "New names" lists the (new) column names. Can a feature be added that avoids printing this information? Something like messages = FALSE. It would be helpful when working with fixed/known inputs for which new column names are specified programmatically.

The following code replicates the display:

read_excel(path = readxl_example('clippy.xlsx'), col_names = FALSE)

Here is the output:

image

@jennybc
Copy link
Member

jennybc commented Aug 9, 2019

readxl affords no control over this and I'm not aware of a tibble option that helps either.

It is ultimately emitted via message() from within the tibble package. My best advice is to muffle it with suppressMessages() like so:

library(readxl)

suppressMessages(
  read_excel(readxl_example("clippy.xlsx"), col_names = FALSE)
)
#> # A tibble: 5 x 2
#>   ...1                 ...2     
#>   <chr>                <chr>    
#> 1 name                 value    
#> 2 Name                 Clippy   
#> 3 Species              paperclip
#> 4 Approx date of death 39083    
#> 5 Weight in grams      0.9

Created on 2019-08-08 by the reprex package (v0.3.0.9000)

@jennybc jennybc closed this as completed Aug 9, 2019
@wgrundlingh
Copy link
Author

My suggestion was to add this as a feature. Here is a simple implementation how I'm currently implementing suppressMessages(); not ideal:

read_excel__ <- read_excel

read_excel <- function (suppress_messages = FALSE, ...) {
  if (suppress_messages) {
    Suppress_Messages <- suppressMessages
  } else {
    Suppress_Messages <- function (args) { args } # NoOp
  }

  return (
    Suppress_Messages(
      read_excel__( ... )
    )
  )  
}

Is this something that seems a better fit with tibble (and therefore would be a better fit here)?

@jennybc
Copy link
Member

jennybc commented Aug 12, 2019

Yeah I do think it's a better issue to ponder in tibble (or conceivably even further upstream). Because ... I'm not going to add an argument to read_excel() for this. So if it happened here, it would require a new wrapper function (what you've made and also a nonstarter) or a readxl option (readxl has no options, so also very unattractive). And if it's an option, it should probably be a tibble option about whether it's chatty about name repair.

@jennybc
Copy link
Member

jennybc commented Aug 12, 2019

Also: what is your context? Is this about an Rmd document or similar?

@jennybc
Copy link
Member

jennybc commented Aug 12, 2019

My reason for asking about .Rmd (or spinning .R) is that you have a really nice way to achieve your goals with the chunk option message = FALSE. Applied to individual chunks or all chunks.

@slyrus
Copy link

slyrus commented Jul 4, 2022

I get that I'm a couple years late to the party but I second the notion that this is a problem with readxl, not with generic tibble construction. IMO, readxl should provide default column names when none or provided - this shouldn't require changing the core tibble API/contract and readxl is in a much better position to understand how many columns are being read than the user code calling it. You could even use col_names = NULL as the flag to provide default colnames (e.g. "Col1" or "ColA") without changing the current behavior.

@sanjmeh
Copy link

sanjmeh commented Jul 30, 2022

New names:
-> `...3` • -> ...4
-> `...5` • -> ...6
-> `...7` • -> ...8
-> `...9` • -> ...10
-> `...11` • -> ...12
-> `...13` • -> ...14
-> `...15` • -> ...16
-> `...17` • -> ...18
-> `...19` • -> ...20

This type of output is not at all helpful.
Why can read_excel() not have an option of suppress names message?

@xaviescacs
Copy link

In my case, I want to skip the first column and I indicate it through col_types with the "_" character which means "skip column". Yet I got the message that the name of this column has been changed, which I couldn't care less about. If I use cols_only() I get the same output. Perhaps is this case It would be reasonable to don't show those messages. I don't want to use suppressMessages() because I don't want to hide any other potentially meaningful messages.

@bhollan
Copy link

bhollan commented Dec 2, 2022

I can confirm this is still happening and still annoying.

@RyanWilkins
Copy link

Would also like a solution to this, please

@jennybc
Copy link
Member

jennybc commented Dec 9, 2022

Thanks to a change in a low-level package (vctrs), we now have a really nice solution to this in readxl and elsewhere. Add .name_repair = "unique_quiet" to the call.

library(readxl)

packageVersion("vctrs")
#> [1] '0.5.1'

read_excel(path = readxl_example('clippy.xlsx'), col_names = FALSE)
#> New names:
#> • `` -> `...1`
#> • `` -> `...2`
#> # A tibble: 5 × 2
#>   ...1                 ...2     
#>   <chr>                <chr>    
#> 1 name                 value    
#> 2 Name                 Clippy   
#> 3 Species              paperclip
#> 4 Approx date of death 39083    
#> 5 Weight in grams      0.9

read_excel(
  path = readxl_example('clippy.xlsx'),
  col_names = FALSE,
  .name_repair = "unique_quiet"
)
#> # A tibble: 5 × 2
#>   ...1                 ...2     
#>   <chr>                <chr>    
#> 1 name                 value    
#> 2 Name                 Clippy   
#> 3 Species              paperclip
#> 4 Approx date of death 39083    
#> 5 Weight in grams      0.9

Created on 2022-12-09 with reprex v2.0.2.9000

Place to read more if you're curious: r-lib/vctrs#1629

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants