juliadataframes.jl

I cannot use @select statement in base/tidier


I'm trying to use select statement but in both examples I'm getting an error message ERROR: LoadError: UndefVarError: @select not defined. Do you know what may causes that?

#DF
names = ["Sally", "Bob", "Alice", "Hank"]
grades = [1, 5, 8.5, 4]
df = DataFrame(; name=names, grades=grades)

#Base
@chain df begin
    @transform(:grades_new = :grades/2)
    @subset(:name .== "Sally")
    @select(:grades)
end

#Tidier
@chain df begin
    @mutate(grades_new = grades/2)
    @filter(name == "Sally")
    @select(grades)
end

Solution

  • There is a conflict with DataFramesMeta.@select and Tidier.@select.
    Use:

    using DataFrames, Chain, DataFramesMeta, Tidier
    
    #DF
    names = ["Sally", "Bob", "Alice", "Hank"]
    grades = [1, 5, 8.5, 4]
    df = DataFrame(; name=names, grades=grades)
    
    #DataFramesMeta
    @chain df begin
        @transform(:grades_new = :grades/2)
        @subset(:name .== "Sally")
        DataFramesMeta.@select(:grades)
    end
    #1×1 DataFrame
    # Row │ grades  
    #     │ Float64 
    #─────┼─────────
    #   1 │     1.0
    
    #Tidier
    @chain df begin
        @mutate(grades_new = grades/2)
        @filter(name == "Sally")
        Tidier.@select(grades)
    end
    #1×1 DataFrame
    # Row │ grades  
    #     │ Float64 
    #─────┼─────────
    #   1 │     1.0
    

    In case either DataFramesMeta or Tidier is used, there is no need to qualify the module. But when they are used together, the module need to be given to know which @select will be used.