Is there a way to provide support for the types from another package without actually requiring that package? For example, say I wanted to make the following type in my package:
struct Foo{T<:Real} <: AbstractArray{T,2}
table::Array{T,2}
samples::Vector{S} where S
features::Vector{R} where R
end
I’d like users of my package to be able to make a Foo from a DataFrame if they want to:
function Foo(df::DataFrame)
return Foo(
Matrix(df[:,2:end]),
names(df[2:end]),
Vector(df[1]))
end
… but I don’t actually need DataFrames for anything else. Is there any way to do this without requiring DataFrames as a dependency and having using DataFrames in my module file?
For completeness, that means in my example above I’d do:
using Requires
struct Foo{T<:Real} <: AbstractArray{T,2}
table::Array{T,2}
samples::Vector{S} where S
features::Vector{R} where R
end
@require DataFrames function Foo(df::DataFrame)
return AbundanceTable(
Matrix(df[:,2:end]),
names(df[2:end]),
Vector(df[1]))
end
Is there a way to declare a type without defining it? So I can refer to its name in method definitions, implying that I support this type if someone else defines it. This would allow me to support types defined in other packages without requiring those packages.