# Is it possible to use a package function without loading the package?

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-use-a-package-function-without-loading-the-package/60813>\
**Category:** General Usage\
**Tags:** package\
**Created:** [May 9, 2021, 7:44am UTC](https://discourse.julialang.org/t/is-it-possible-to-use-a-package-function-without-loading-the-package/60813 "2021-05-09T07:44:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gitboy16](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gitboy16/32/24906_2.png) [@gitboy16](https://discourse.julialang.org/u/gitboy16)\
**Post date:** [May 9, 2021, 7:44am UTC](https://discourse.julialang.org/t/is-it-possible-to-use-a-package-function-without-loading-the-package/60813/1 "2021-05-09T07:44:44Z")

</div>

In R, I would do something like this:

```julia
dt = data.table::fread("data.csv")

```

My understanding is that in Julia I would need to do:

```julia
using DataFrames; using CSV;
df = CSV.File("data.csv") |> DataFrame;

```

The code in Julia is relatively (very) slow vs R for various reason and I understand some people are looking at improving it, but that is not the topic of my question here. My question is:

is there a way to use CSV.File and DataFrame without loading the whole package (like in R) and not having to run `using DataFrames; using CSV;`?

Thank you.  
(I just started Julia this week)

---

<div class="post-metadata">

**Author:** ![lostella](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lostella/32/356_2.png) [@lostella](https://discourse.julialang.org/u/lostella)\
**Post date:** [May 9, 2021, 8:08am UTC](https://discourse.julialang.org/t/is-it-possible-to-use-a-package-function-without-loading-the-package/60813/2 "2021-05-09T08:08:50Z")

</div>

I don’t think so: to use definitions from a module you need to load its code and bring it into scope, which you do with `using` or `import` (see [here](https://docs.julialang.org/en/v1/manual/modules/) for the differences between the two).

I guess the important questions are: what problem do you have with `using` the package? Why would you want to avoid it?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 9, 2021, 8:13am UTC](https://discourse.julialang.org/t/is-it-possible-to-use-a-package-function-without-loading-the-package/60813/3 "2021-05-09T08:13:35Z")

</div>

> [@gitboy16](#):
>
> In R, I would do something like this:
> 
> ```julia
> dt = data.table::fread("data.csv")
> 
> ```

I think that R also quietly loads the package, eg `?"::"` says that

> The package namespace will be loaded if it was not loaded before the call

If you just care about namespace management, use something like

```julia
using DataFrames: DataFrame
import CSV

```

so that no other symbols end up in the namespace.

---

<div class="post-metadata">

**Author:** ![gitboy16](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gitboy16/32/24906_2.png) [@gitboy16](https://discourse.julialang.org/u/gitboy16)\
**Post date:** [May 9, 2021, 12:25pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-a-package-function-without-loading-the-package/60813/4 "2021-05-09T12:25:21Z")

</div>

It is to avoid conflict with functions that have the same name which actually happens in R. In R you have the following:

```julia
> dt = data.table::fread("Downloads/dataset.csv")
> dt = fread("Downloads/dataset.csv")
Error in fread("Downloads/dataset.csv") : could not find function "fread"

```

Meaning `fread` is not in scope.  
But I guess that if I use `CSV.File` and `DataFrames.DataFrame` I am making it clear which function from which package I am using.  
Thank you for your answers (which I believe answer my question).

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [May 9, 2021, 4:34pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-a-package-function-without-loading-the-package/60813/5 "2021-05-09T16:34:43Z")

</div>

If you just do `using DataFrames: DataFrames` (note that this is the same name as the module - you’re quite literally only bringing the module name into scope, not the exported names), you can do `DataFrames.DataFrame(...)` to qualify which you mean.

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [May 9, 2021, 7:29pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-a-package-function-without-loading-the-package/60813/6 "2021-05-09T19:29:00Z")

</div>

Is there a difference between `import DataFrames` and `using DataFrames: DataFrames`?

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [May 10, 2021, 7:06am UTC](https://discourse.julialang.org/t/is-it-possible-to-use-a-package-function-without-loading-the-package/60813/7 "2021-05-10T07:06:35Z")

</div>

No.
