Invoking the @filter
function in the TidierData package, I’m trying to use the the !!
syntax to refer to a variable not in the data frame as described here:
If you want to refer to an object a that is defined outside of the data frame, then you can write !!a, which we refer to as “bang-bang interpolation.”
Trying this out, it works with some variables but not if variables are other data frames.
using DataFrames
using Tidier
First case - regular variable. The following example works.
julia> df = DataFrame(x = 1:5)
5×1 DataFrame
Row │ x
│ Int64
─────┼───────
1 │ 1
2 │ 2
3 │ 3
4 │ 4
5 │ 5
julia> y = 5
5
julia> @filter(df, x != !!y)
4×1 DataFrame
Row │ x
│ Int64
─────┼───────
1 │ 1
2 │ 2
3 │ 3
4 │ 4
Second case - the external variable is another data frame. This doesn’t work.
julia> df2 = DataFrame(y = 5)
1×1 DataFrame
Row │ y
│ Int64
─────┼───────
1 │ 5
julia> @filter(df, x != !!df2.y)
ERROR: UndefVarError: `df2` not defined in `TidierData`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
[1] (::var"#22#24")(x::Vector{Int64})
@ Main ~/.julia/packages/TidierData/Dw20l/src/parsing.jl:141
[2] (::DataFrames.var"#610#611"{var"#22#24"})(x::Vector{Int64})
@ DataFrames ~/.julia/packages/DataFrames/kcA9R/src/abstractdataframe/subset.jl:66
[3] _transformation_helper(df::DataFrame, col_idx::Int64, ::Base.RefValue{Any})
@ DataFrames ~/.julia/packages/DataFrames/kcA9R/src/abstractdataframe/selection.jl:562
[4] select_transform!(::Base.RefValue{Any}, df::DataFrame, newdf::DataFrame, transformed_cols::Set{Symbol}, copycols::Bool, allow_resizing_newdf::Base.RefValue{Bool}, column_to_copy::BitVector)
@ DataFrames ~/.julia/packages/DataFrames/kcA9R/src/abstractdataframe/selection.jl:805
[5] _manipulate(df::DataFrame, normalized_cs::Vector{Any}, copycols::Bool, keeprows::Bool)
@ DataFrames ~/.julia/packages/DataFrames/kcA9R/src/abstractdataframe/selection.jl:1783
[6] manipulate(df::DataFrame, cs::Any; copycols::Bool, keeprows::Bool, renamecols::Bool)
@ DataFrames ~/.julia/packages/DataFrames/kcA9R/src/abstractdataframe/selection.jl:1703
[7] select(df::DataFrame, args::Any; copycols::Bool, renamecols::Bool, threads::Bool)
@ DataFrames ~/.julia/packages/DataFrames/kcA9R/src/abstractdataframe/selection.jl:1303
[8] _get_subset_conditions(df::DataFrame, ::Base.RefValue{Any}, skipmissing::Bool, threads::Bool)
@ DataFrames ~/.julia/packages/DataFrames/kcA9R/src/abstractdataframe/subset.jl:113
[9] subset(df::DataFrame, args::Any; skipmissing::Bool, view::Bool, threads::Bool)
@ DataFrames ~/.julia/packages/DataFrames/kcA9R/src/abstractdataframe/subset.jl:284
[10] macro expansion
@ ~/.julia/packages/TidierData/Dw20l/src/TidierData.jl:424 [inlined]
[11] top-level scope
@ REPL[8]:1
Is there something I’m missing?
Overall, it’s really intuitive coming from R and a nice set of packages here.
Thanks in advance.