# Find the location of the function I'm calling?

**URL:** https://discourse.julialang.org/t/find-the-location-of-the-function-im-calling/55856
**Category:** General Usage
**Created:** [February 23, 2021, 3:06pm UTC](https://discourse.julialang.org/t/find-the-location-of-the-function-im-calling/55856 "2021-02-23T15:06:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Daneel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daneel/32/175_2.png) [@Daneel](https://discourse.julialang.org/u/Daneel)
#### Post date: [February 23, 2021, 3:06pm UTC](https://discourse.julialang.org/t/find-the-location-of-the-function-im-calling/55856/1 "2021-02-23T15:06:39Z")

</div>

How can I figure out where the calling function is located? I want an include to be relative to the function itself.

---

<div class="post-metadata">

### Author: ![Skoffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skoffer/32/378_2.png) [@Skoffer](https://discourse.julialang.org/u/Skoffer)
#### Post date: [February 23, 2021, 3:10pm UTC](https://discourse.julialang.org/t/find-the-location-of-the-function-im-calling/55856/2 "2021-02-23T15:10:45Z")

</div>

Not sure I understand the “include relative to the function” part, but you can find where the function is located with the help of `@which` macro

```julia
julia> using Plots

julia> @which plot([1], [1])
plot(args...; kw...) in Plots at /home/skoffer/.julia/packages/Plots/oZheM/src/plot.jl:49

```

---

<div class="post-metadata">

### Author: ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)
#### Post date: [February 23, 2021, 5:46pm UTC](https://discourse.julialang.org/t/find-the-location-of-the-function-im-calling/55856/3 "2021-02-23T17:46:15Z")

</div>

It sounds like you want `stacktrace()` to me which returns an Array containing the stack:

```julia
julia> example() = stacktrace()
example (generic function with 1 method)

julia> example_1() = example()
example_1 (generic function with 1 method)

julia> example_1()
15-element Array{Base.StackTraces.StackFrame,1}:
 example at REPL[7]:1 [inlined]
 example_1() at REPL[8]:1
 top-level scope at REPL[9]:1
 eval(::Module, ::Any) at boot.jl:331
 eval_user_input(::Any, ::REPL.REPLBackend) at REPL.jl:134
 repl_backend_loop(::REPL.REPLBackend) at REPL.jl:195
 start_repl_backend(::REPL.REPLBackend, ::Any) at REPL.jl:180
 run_repl(::REPL.AbstractREPL, ::Any; backend_on_current_task::Bool) at REPL.jl:292
 run_repl(::REPL.AbstractREPL, ::Any) at REPL.jl:288
 (::Base.var"#807#809"{Bool,Bool,Bool,Bool})(::Module) at client.jl:399
 #invokelatest#1 at essentials.jl:710 [inlined]
 invokelatest at essentials.jl:709 [inlined]
 run_main_repl(::Bool, ::Bool, ::Bool, ::Bool, ::Bool) at client.jl:383
 exec_options(::Base.JLOptions) at client.jl:313
 _start() at client.jl:506

```

So you want want `stacktrace()[2]` as the calling method, I think.

---

<div class="post-metadata">

### Author: ![Daneel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daneel/32/175_2.png) [@Daneel](https://discourse.julialang.org/u/Daneel)
#### Post date: [May 4, 2021, 1:05pm UTC](https://discourse.julialang.org/t/find-the-location-of-the-function-im-calling/55856/4 "2021-05-04T13:05:23Z")

</div>

I finally found it, `@ __FILE__ ` or `@ __DIR__ `.

[Base.@ **FILE**](https://docs.julialang.org/en/v1/base/base/#Base.@ __FILE__ )
