Error Loading CSV Files using ~/filepath.csv


I’m new to Julia & don’t understand why when using ‘~’ to specify start of my filepath, FileIO.load() gives a

Load Error:

using FileIO, CSVFiles, DataFrames

obj1 = load("~/Desktop/solar power by country.csv")

obj1 = load("~/Desktop/solar power by country.csv")
ERROR: LoadError: ArgumentError: No file exists at given path: ~/Desktop/solar power by country.csv
 [1] checkpath_load
   @ ~/.julia/packages/FileIO/u9YLx/src/loadsave.jl:167 [inlined]
 [2] load(::String; options::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ FileIO ~/.julia/packages/FileIO/u9YLx/src/loadsave.jl:110
 [3] load(::String)
   @ FileIO ~/.julia/packages/FileIO/u9YLx/src/loadsave.jl:110
 [4] top-level scope
   @ Untitled-1:3
in expression starting at Untitled-1:3

But neither the ./filepath or absolute path gives that error:

obj2 = load("./Desktop/solar power by country.csv")
obj3 = load("/home/srikrishna/Desktop/solar power by country.csv")

Am I missing something in my understanding? This is in VS code.

In Jupyter ~ automatically turns into /home/srikrishna.


You mean python? Pretty sure Julia (which is the Ju in Jupyter) never expands. One trick is to hit tab after typing "~/

Or use expanduser:

load(expanduser("~/Desktop/solar power by country.csv"))

Other option, use homedir to indicate the home:

load(joinpath(homedir(), "Desktop", "solar power by country.csv"))

Tab complete does work in both REPL & Jupyter for ~.
But not in VSCode editor :confused:


Thanks for the knowledge drop!

~ is supplied by the shell (e.g. Bash), not the operating system

So it is not recognised by System calls as your home directory but as just another filename

Some shells do not provide it e.g. rc from plan9ports

matt@pox:~$ rc
% ls ~
ls: cannot access '~': No such file or directory
% echo hi > ~
% ls -l
total 608
-rw-r--r-- 1 matt matt      3 Feb 12 22:03 '~'
matt@pox:~$ cat ~
cat: /home/matt: Is a directory
matt@pox:~$ cat "~"




Peek 2022-02-12 21-07

Yes. It works everywhere but the editor pane in VSCode.