Skip to main content eteppo

Print Names Of Objects in the Global Environment in R

Published: 2023-08-04
Updated: 2023-08-04

How to see which objects you have in the global environment in R if you’re not using an IDE that shows them to you? Here’s one way to add them into a terminal message.

message_globalenv <- function() {
  msg <- "R Global Environment:\n"
  for (object in base::ls(name = base::globalenv(), all.names = TRUE)) {
    msg <- paste0(msg, " * ", object, "\n")
  }
  message(msg)
}