Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting working directory: Julia versus R

Tags:

In R, starting from any working directory, I can do

setwd("~/Desktop") 

and this is consistent with how my linux distribution interprets cd at the command line. But Julia does not seem to recognize the ~/ notation:

julia> cd("~/Desktop") ERROR: chdir ~/Desktop: No such file or directory  in systemerror at error.jl:38  in cd at file.jl:13 

Is this a bug?

like image 633
zkurtz Avatar asked Jul 19 '14 14:07

zkurtz


People also ask

How do I change my working directory in Julia?

The command to change working directory is cd(dir::AbstractString=homedir()).

What does it mean to set working directory in R?

The working directory is just a file path on your computer that sets the default location of any files you read into R, or save out of R. In other words, a working directory is like a little flag somewhere on your computer which is tied to a specific analysis project.


2 Answers

The idiom is just different as you can see from the source. If you invoke cd() without arguments, it defaults to the home directory. The function homedir() can be used to prepend the home directory.

julia> homedir() "/Users/jeffw"  julia> cd("/")  julia> pwd() "/"  julia> cd()  julia> pwd() "/Users/jeffw" 

Combining things

julia> cd("$(homedir())/Desktop")  julia> pwd() "/Users/jeffw/Desktop" 
like image 144
waTeim Avatar answered Sep 17 '22 13:09

waTeim


The problem is that Julia doesn't expand the ~. You need to manually provide the full path. This is being worked on, but I'm on my phone right now and can't find issue.

like image 26
IainDunning Avatar answered Sep 21 '22 13:09

IainDunning