# Check whether the type of an object is from a package not loaded

**URL:** <https://discourse.julialang.org/t/check-whether-the-type-of-an-object-is-from-a-package-not-loaded/31344>\
**Category:** General Usage\
**Created:** [November 21, 2019, 10:24am UTC](https://discourse.julialang.org/t/check-whether-the-type-of-an-object-is-from-a-package-not-loaded/31344 "2019-11-21T10:24:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)\
**Post date:** [November 21, 2019, 10:24am UTC](https://discourse.julialang.org/t/check-whether-the-type-of-an-object-is-from-a-package-not-loaded/31344/1 "2019-11-21T10:24:03Z")

</div>

I have a package `A` in which I’d like to have a functionality `foo` which works on `AbstractArray` but does something different on `LazyArrays.ApplyArray`.  
**twist** : I would like not to have `LazyArrays` loaded in `A`.

Is this possible?

### a bit of a longer explanation

CSV, in its threaded mode, generates `LazyArrays.ApplyArray`, this causes a bit of an issue with something we’re doing in ScientificTypes.jl (issue [here](https://github.com/JuliaData/Tables.jl/issues/122) for context but otherwise irrelevant I would think).

A hacky workaround is to check the propertynames of the object as it turns out `ApplyArray` have a `:f` and `:args` field, but that’s really not great and I can’t robustly assume that’s a one-to-one signature.

I can’t do something like `typeof(vec) <: LazyArrays.ApplyArray` because that requires loading `LazyArrays` in `ScientificTypes` which I’d rather not do to keep the package as light as possible.

Thanks!

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [November 21, 2019, 1:01pm UTC](https://discourse.julialang.org/t/check-whether-the-type-of-an-object-is-from-a-package-not-loaded/31344/2 "2019-11-21T13:01:46Z")

</div>

Are you aware of [https://github.com/MikeInnes/Requires.jl](https://github.com/MikeInnes/Requires.jl)?

---

<div class="post-metadata">

**Author:** ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)\
**Post date:** [November 21, 2019, 2:03pm UTC](https://discourse.julialang.org/t/check-whether-the-type-of-an-object-is-from-a-package-not-loaded/31344/3 "2019-11-21T14:03:44Z")

</div>

Yes, thanks. I’m looking for a package-free way of doing this though (or at least something that doesn’t double the package loading time).

I think I found a way though, the key thing is that `typeof(object)` does return `LazyArrays.ApplyArray` but I can’t directly compare that because LazyArrays is not loaded. However I can compare it as a String…

So for someone who may be looking for a similar solution, here’s something that works and is better than checking the propertynames:

```julia
julia> Threads.nthreads()
2

julia> using RDatasets; boston = dataset("MASS", "Boston");

julia> typeof(boston.Chas)
LazyArrays.ApplyArray{Int64,1,typeof(vcat),Tuple{Array{Int64,1},Array{Int64,1}}}

julia> "$(typeof(boston.Chas))"
"LazyArrays.ApplyArray{Int64,1,typeof(vcat),Tuple{Array{Int64,1},Array{Int64,1}}}"

julia> startswith("$(typeof(boston.Chas))", "LazyArrays.ApplyArray")
true

julia> typeof(boston.Chas) <: LazyArrays.ApplyArray
ERROR: UndefVarError: LazyArrays not defined
Stacktrace:
 [1] top-level scope at none:0

```

PS: for completeness it should also check whether it’s just `ApplyArray` (in case `LazyArrays` is loaded in the env)

Happy to learn of other ways though or to consider why using the above hack could be problematic…
