Skip to content

passmissing and using higher order functions in macros #170

@ghyatzo

Description

@ghyatzo

Hello,

Today I had the need to do something similar:

passmissing(f) = x -> ismissing(x) ? missing : f(x)

f = passmissing(uppercase)
@chain dat begin
	@mutate(COL_A = f(COL_A))
	@distinct(COL_ID)
end

this is the version that works, but I've also tried:

  • @mutate(dat, COL_A = passmissing(!!uppercase)(COL_A))
  • @mutate(dat, COL_A = passmissing(uppercase)(COL_A))
  • @mutate(dat, COL_A = passmissing($uppercase)(COL_A))

but all three fail.

the first with a:

UndefVarError: passmissing($(Expr(:escape, :uppercase))) not defined in TidierData.

the second with

ArgumentError: column name :uppercase not found in the data frame

the third with

UndefVarError: passmissing($uppercase) not defined in TidierData.

Now, I'm definitely stumbling around, but I was wondering if

  1. there was a way of signaling that an identifier is a main module symbol and not a column name
  2. in a bit of XY-problem fashion, is there a blessed way of replicating the passmissing functionality? skipmissing will return columns that can be smaller, leading to all sort of issues in certain workflows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions