Setting working directory: Julia versus R

2019-01-25 04:15发布

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?

2条回答
相关推荐>>
2楼-- · 2019-01-25 04:26

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"
查看更多
手持菜刀,她持情操
3楼-- · 2019-01-25 04:42

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.

查看更多
登录 后发表回答