Define methods for packages without importing

Say that I got a package Foo and want my package to include some methods especially for handling DataFrames, and plots from Plots and Gadfly.

To do this, I could define something like

module Foo

import DataFrames
import Gadfly
import Plots

foo(x::DataFrames.DataFrame) = DataFrames.first(x, 5)
foo(x::Gadfly.Plot) = x
foo(x::Plots.Plot) = x

end # module

However, if an user now want to use Foo, the user has to install and precompile DataFrames, Plots and Gadfly even if the user has no intention of using any of these.

Is is possible to define the methods in Foo without importing the packages? (Or am I completely wrong, and would these imports not really affect the user?)

Check out https://github.com/JuliaPackaging/Requires.jl which should do what you’re looking for.

4 Likes