Code Monkey home page Code Monkey logo

Comments (7)

piever avatar piever commented on August 12, 2024

To make the discussion more complete, here is an example of a simplified @with macro called @given:

macro given(d, x)
    esc(_given(d,x))
end

_given(d, x) = x

function _given(d, x::Expr)
    (x.head == :quote) && return :(haskey($d, $x) ? $d[$x] : $x)
    (x.head == :call) && x.args[1] == :^ && length(x.args) == 2 && return x.args[2]
    return Expr(x.head, _given.(d, x.args)...)
end

Usage:

using StatPlots, DataFrames,RDatasets
iris = RDatasets.dataset("datasets","iris")
@given iris scatter(:PetalLength, :PetalWidth, group = :Species, legend = :topleft)
iris[:topleft] = rand(150)
@given iris scatter(:SepalLength, :SepalWidth, group = :Species, legend = ^(:topleft))

Advantages over @with :

  • No need to escape the symbols unless there actually is ambiguity
  • No DataFramesMeta dependency
  • It's easy to adjust it to include other datasources, provided they allow extracting one column (which I'm assuming all of them do)

from statsplots.jl.

piever avatar piever commented on August 12, 2024

I am sure I had written this already here, but apparently I forgot to post it: as a first non-breaking step, if there is consensus, I'd be happy to make a PR with the @given macro, mentioning it instead of @with in the README. Of course we should maybe spend some time figuring out what's the best name for @given.

Even if we get the plot(df,...) syntax to work, it's good to also have the macro version because it retains some advantages that are just impossible to achieve with a function:

  • Manipulating columns doesn't require wrapping everything in a :(). For example one can write
@given iris scatter(log.(:PetalLength), :PetalWidth .+ 1, group = :SepalWidth .> 3, legend = :topleft)

and it would just work (I'm even tempted to add a where kw to also select what data to plot in the plot command)

  • Manipulating columns doesn't require a runtime eval

@mkborregaard : what's your take on this?

from statsplots.jl.

mkborregaard avatar mkborregaard commented on August 12, 2024

Sorry for not responding - I'm reading and thinking carefully but haven't had a chance to do it justice - please have a little patience :-)

from statsplots.jl.

kescobo avatar kescobo commented on August 12, 2024

My gut reaction is that adding additional syntax would be unfortunate given the goals of the Plots.jl ecosystem. Then again, the functionality is more important, and if this would fix some of the issues with using DataFrames to their full extent...

Alas, I don't understand enough of the backend stuff to comment on implementation.

from statsplots.jl.

mkborregaard avatar mkborregaard commented on August 12, 2024

I think this looks really cool. It's certainly a lot simpler than the current non-macro framework!! If you'd make a PR with the given macro I'll try it out in some of the other cases I've been considering. This involves e.g. passing a part of a DataFrame as a matrix but that should be possible with [:a :b] here I think.

I think we should be sure to be compatible not just with DataFrames but with abstract table formats such as DataTables, JuliaDB, IndexedTables etc but I'll need to check the current status of those to see if that could work.

Another thing I'd like the macro to do was to replace all NAs with NaNs for number fields, and "" / Symbol() for string/symbol fields, so that the plot function doesn't automatically fail when passing it a DataFrame with NAs in it.

In short, I agree that a macro approach is the best way to deal with table symbols.

from statsplots.jl.

piever avatar piever commented on August 12, 2024

Your intuition is correct, using the horizontal concatenation syntax:
@given iris corrplot([:SepalLength :SepalWidth :PetalLength :PetalWidth])
corrplot

I'll add the missing value part and make a PR tomorrow.

As for the support of any table-like structure, maybe the easiest is to support IterableTables? I'm also not sure what the state of affairs is in the data echosystem...

from statsplots.jl.

mkborregaard avatar mkborregaard commented on August 12, 2024

This should be fully resolved now.

from statsplots.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.