`address(x)` fails when x is the missing argument

Open
#5,664 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
data

Research direction

Reproduce the failure with the supplied R examples for address(x), including the missing argument case, then trace the address implementation through the Caddress entry point. Compare the proposed maybe_missing workaround and verify that ordinary and missing arguments return the expected addresses, including the function-call example.

Written by the indexing model from the issue text.

Description

bug

The code

library(data.table)
x <- quote(list(x=))[[2]]   # extract the missing argument

missing(x)  # TRUE

address(x)  # Error in eval(substitute(x), parent.frame()) : 
            # argument "a" is missing, with no default

{function(x) address(x) }()  # same error

will fail when x is the missing argument. I think it is a bug since x is a legitimate variable.
This is a situation similar to #1521 of rlang.
So i propose to apply the same workaround here (see maybe_missing of rlang for case.)

#PROPOSED SOLUTION:
address2  <- function (x) {
  
  maybe_missing <- function (x, default = quote(list(x=))[[2]]) {
    if (missing(x)) default else x 
  }
  .Call("Caddress", eval(substitute(maybe_missing(x)), parent.frame()), PACKAGE= "data_table")
}


# TEST:
x <- quote(list(x=))[[2]]
y <- "something"

address2(x)
address2(y)

stopifnot(address2(y) == address(y))  #OK

stopifnot(paste0("0x",address2(x)) == rlang::obj_address(x))  #OK
stopifnot(paste0("0x",address2(y)) == rlang::obj_address(y))  #OK

{function(x) address2(x)}()  # OK

Hope may be of help.
Tks.

Dominant language
R
Stars
3.9k
Forks
1.1k
Avg merge
14h 4m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rdatatable/data.table

All issues in Rdatatable/data.table

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.