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

posts/2023-12-07-view/ #25

Open
utterances-bot opened this issue Dec 7, 2023 · 2 comments
Open

posts/2023-12-07-view/ #25

utterances-bot opened this issue Dec 7, 2023 · 2 comments

Comments

@utterances-bot
Copy link

Mike Mahoney - Why is View() capitalized, anyway?

And down the rabbit hole we go.

https://www.mm218.dev/posts/2023-12-07-view/

Copy link

What a journey!

Something that broke my mind is that lowercase view is exported from tibble and dplyr. I had a student write some code and I remember saying, "oh wait, it needs to be capitalised, for reasons, I dunno", and they hit Enter and were like "I never capitalise it?". But then that's because they were using tidyverse stuff, so they never went through the pain!

@yihui
Copy link

yihui commented Dec 11, 2023

The reason that

getOption("defaultPackages") |> 
  setdiff("datasets") |> 
  vapply(\(x) paste0("package:", x), character(1)) |> 
  ls() |> 
  strsplit("") |> 
  Filter(f = \(x) x[[1]] %in% LETTERS) |> 
  vapply(paste0, character(1), collapse = "")

didn't return all capitalized function names is that ls() is not vectorized. You passed a vector to it, but it will only use the first element, i.e., you were essentially listing functions in the utils package. To see this problem, you may run:

ls(c('package:utils', 'package:grDevices'))

and you will see the grDevices package is ignored.

This is what I'd do:

ns = lapply(getOption("defaultPackages"), getNamespace)
nm = unlist(lapply(ns, ls))
sort(grep('^[A-Z]', nm, value = TRUE))

In the current version of R, there are 500 such functions.

But it may make more sense to see exported functions only, because they are user-faced. In that case, you can do:

nm = lapply(getOption("defaultPackages"), getNamespaceExports)
sort(grep('^[A-Z]', unlist(nm), value = TRUE))

There are 85 such functions.

Anyway, I don't know why Viewer() is capitalized. Perhaps only the author knows, and I doubt anyone wants to ask him... Sometimes naming is just arbitrary. Even when a project is developed by a single person, it's not uncommon to see inconsistencies, not to mention multiple authors collaborating on a project. A style guide could help, but it could also mean compromises, which can be hard sometimes.

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

3 participants