In R, I would do something like this:
dt = data.table::fread("data.csv")
My understanding is that in Julia I would need to do:
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;?
(I just started Julia this week)
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
import (see here 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?
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
using DataFrames: DataFrame
so that no other symbols end up in the namespace.
It is to avoid conflict with functions that have the same name which actually happens in R. In R you have the following:
> dt = data.table::fread("Downloads/dataset.csv")
> dt = fread("Downloads/dataset.csv")
Error in fread("Downloads/dataset.csv") : could not find function "fread"
fread is not in scope.
But I guess that if I use
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).
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.
Is there a difference between
import DataFrames and
using DataFrames: DataFrames?