Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia package data files and absolute/relative paths

Tags:

julia

I'm creating a package in Julia and have followed the Package Development section of the Docs.

One of my functions opens and reads in a data file (mydata.txt) that I'm storing in the package directory.

Everything works pretty great when I run the Julia from the package directory but not so great when I run the tests or run Julia from a different directory because it doesn't know where to find that data file.

I thought I could just do something like:

datapath = Pkg.dir("MyPkg") * "/data/"

to get an absolute path to the file but it still doesn't seem to work.

What is the correct way to provide an absolute file path for data in a package?

like image 569
Ellis Valentiner Avatar asked Dec 19 '22 18:12

Ellis Valentiner


1 Answers

In order to properly handle multi-platform directory files and paths, use Julia's built-in joinpath method:

joinpath(Pkg.dir("MyPkg"), "data", "mydata.txt")

The resulting path will be valid in every platform.

like image 199
Imanol Luengo Avatar answered Dec 28 '22 10:12

Imanol Luengo