Difference between ls() and objects()

They are identical. Looking at the source code they're literally just different names for the same code as can been seen here: https://github.com/wch/r-source/blob/bfe73ecd848198cb9b68427cec7e70c40f96bd72/src/library/base/R/attach.R#L200

The relevant snippet:

ls <- objects <-
    function (name, pos = -1L, envir = as.environment(pos), all.names = FALSE,
              pattern, sorted = TRUE)
{

We can also check that they have identical code from within R

> all.equal(body(objects), body(ls))
[1] TRUE

Tags:

R