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

tables() fails: argument "..." is missing, with no default #5197

Closed
greg-minshall opened this issue Oct 5, 2021 · 6 comments · Fixed by #5199
Closed

tables() fails: argument "..." is missing, with no default #5197

greg-minshall opened this issue Oct 5, 2021 · 6 comments · Fixed by #5199
Milestone

Comments

@greg-minshall
Copy link

the following code generates an error. possibly because the current environment has three dots ("...").

  a <- function(...) data.table::tables()
  a()

the error is

Error in get(x, envir = env) : argument "..." is missing, with no default

# Output of sessionInfo()

R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux

Matrix products: default
BLAS: /usr/lib/libopenblasp-r0.3.15.so
LAPACK: /usr/lib/liblapack.so.3.10.0

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_GB.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] compiler_4.1.0 data.table_1.14.3

@MichaelChirico
Copy link
Member

Here is a quick fix in case you're stuck:

a <- function(...) data.table::tables(env = .GlobalEnv)
a()
# No objects of class data.table exist in .GlobalEnv 

@MichaelChirico
Copy link
Member

BTW, my gut feeling is that env = .GlobalEnv is closer to what you're after anyway. When used in a function like you've provided, by default tables() will only list the tables in that function's environment.

@greg-minshall
Copy link
Author

hi, Michael, thanks for the quick response (and already a pull request). in fact, i'm trying to walk back the call stack, finding the data tables in each frame. (i have a process that runs for an hour or so, very little lives in the global environment, and i'm curious about memory usage.) at the end, i do some lame unique( as a hack to get rid of duplicates.

just since i have you, if you've any idea on how to find aliases (to de-duplicate), i'm all ears. fyi, this is the code so far:

  dts <- NULL
  eh <- environment()
  for (i in 1:sys.nframe()) {
    dts <- rbind(dts,
                 tables(env = sys.frame(i), silent = TRUE))
  }
  dts <- data.table(unique(as.data.frame(dts)))

where the "shell game" on the last line is because, amusingly, the data.table that tables() returns seems to not be unique'i'fiable by data.table. :) because, i guess, of the list of column names.

@MichaelChirico
Copy link
Member

Some tips:

(1) replace COLS := sapply(COLS, toString) to get unique.data.table working again

(2) if you're looking for true duplicates (sharing the same memory), you might look at the address() of each table you find:

# within the loop
dts[, address := sapply(NAME, function(nm) address(sys.frame(i)[[nm]]))]

ought to work.

(3) you might want idcol = TRUE or idcol = 'frame' to record which frame each table came from

@greg-minshall
Copy link
Author

Michael, thanks for the tips. address(), in particular, i'm very happy to know. my code (just because) is now:

  exceptions <- 0
  dts <- rbindlist(
    lapply(
      seq_len(sys.nframe()),
      function(i) {
        ##  deal with a bug in data.table
        ##  https://github.com/Rdatatable/data.table/issues/5197
        dt <- tryCatch(
          dt <- tables(env = sys.frame(i), silent = TRUE),
          error = function(e) {
            exceptions <<- exceptions + 1L
            return(data.table())
          })
        if (nrow(dt)) {
          return(data.table(dt, ID = i))
        } else {
          return(NULL)
        }
      }))

(exceptions is to track how many frames i can't examine; assuming your pull makes it into the development branch (i'm addicted to env = list(...)), i can simplify.)

cheers.

@mattdowle mattdowle added this to the 1.14.3 milestone Oct 8, 2021
@greg-minshall
Copy link
Author

thanks very much -- and for the new dev release with this fix. (happiness is simplified code! :)

cheers.

@jangorecki jangorecki modified the milestones: 1.14.9, 1.15.0 Oct 29, 2023
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

Successfully merging a pull request may close this issue.

4 participants