# \`include\` calls in a Julia package

**URL:** <https://discourse.julialang.org/t/include-calls-in-a-julia-package/117558>\
**Category:** General Usage\
**Tags:** question, package, development\
**Created:** [July 28, 2024, 3:01am UTC](https://discourse.julialang.org/t/include-calls-in-a-julia-package/117558 "2024-07-28T03:01:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Santiago\_Lopez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/santiago_lopez/32/46298_2.png) [@Santiago\_Lopez](https://discourse.julialang.org/u/Santiago_Lopez)\
**Post date:** [July 28, 2024, 3:01am UTC](https://discourse.julialang.org/t/include-calls-in-a-julia-package/117558/1 "2024-07-28T03:01:31Z")

</div>

Assume we are developing a package called `MyPkg`. Step 3 of [this tutorial](https://julialang.org/contribute/developing_package/) states that, in order to export our package functions, we should add the following to our `src/MyPkg.jl` file:

- A statement `export my_function`
- A statement `include("file_with_functions.jl")`

Fair enough. However, in a complex package, we may have many inter-dependent files. Say our `src` folder has files `A.jl` and `B.jl`, and say `B.jl` uses functions from `A.jl` and thus contains the statement `include("A.jl")`.

Following the instructions of the tutorial, we should write the following in our `MyPkg.jl` file:

```julia
export first_function_of_A
...
export last_function_of_A
export first_function_of_B
...
export last_function_of_B

include("A.jl")
include("B.jl")

```

However, since `B.jl` already has an expression `include("A.jl")`, this leads to a double evaluation of this expression. When importing the package, we will get `Warning: Replacing docs for...` for all functions of `A.jl`.

What is the best practice for structuring the `MyPkg.jl` file in the context of multiple files, some of which source (`include`) others? The practice should not only avoid repeated calls to `include` but ensure that everything is exported in the package.

Thanks!

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [July 28, 2024, 3:33am UTC](https://discourse.julialang.org/t/include-calls-in-a-julia-package/117558/2 "2024-07-28T03:33:17Z")

</div>

B.jl should NOT contain any include statement. Not needed.

---

<div class="post-metadata">

**Author:** ![Satvik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/satvik/32/20486_2.png) [@Satvik](https://discourse.julialang.org/u/Satvik)\
**Post date:** [July 28, 2024, 3:58am UTC](https://discourse.julialang.org/t/include-calls-in-a-julia-package/117558/3 "2024-07-28T03:58:59Z")

</div>

One common way is to write `MyPkg.jl` like so:

```julia

# External packages used anywhere
using Arrow
using DataFrames

#exports
export function1
export function2

# Internal files
include("A.jl")
include("B.jl")

```

Since `A.jl` will already have been included, `B.jl` will have access to its code. So you don’t need to worry about reimporting `A` in `B`.
