How to automatically use packages at startup?


#1

Is it possible to have the REPL automatically call using PackageName at startup? This seems very useful with 0.7 (using LinearAlgebra), etc.

I tried to find it the Julia docs, maybe the answer could be added to the FAQ under “Sessions and the REPL”.


#2

There is ~/.juliarc.jl, which is executed by default for REPL and non-interactive sessions. You can disable it with the option --startup-file={yes|no} Load ~/.juliarc.jl.

It’s mentioned in a few places in the docs (easy to find if you know that it’s juliarc.jl` …), e.g.: https://docs.julialang.org/en/stable/manual/getting-started/#Getting-Started-1


#3

Thanks! (I remembered there was a file, just couldn’t remember the name.)

This should be made very prominent in preparation for 0.7. (which is almost unusable without it, as if you forget using LinearAlgebra or using Random you have to start the REPL over again.)


#4

What does rc stand for? juliarc seems like a particularly unmemorable name


#5

from http://www.catb.org/jargon/html/R/rc-file.html

[An rc file is a ] Script file containing startup instructions for an application program (or an entire operating system), usually a text file containing commands of the sort that might have been invoked manually once the system was running but are to be executed automatically each time the system starts up.

Its etymology is obscure (click the link for details), but it’s a unix convention (for example .bashrc).


#6

I would say it is particularly memorable, looking at other examples:

.bashrc
.octaverc
.screenrc
.vimrc
.initrc

etc.


#7

I may be missing something, but can’t you just load anything later if you need it? Why do you need to restart the REPL?


#8

The namespace gets polluted, so you have to then do Random.rand to call rand


#9

More evidence that we need a unix sans abbreviations. Programming should be easier than playing nethack.


#10

I see, I think this was a blind spot for me given my workflow (doing almost everything in modules, with Revise.jl).


#11

1.0 won’t be as bad as it’ll just error out with UndefVarError. It’s the deprecation message that makes this so painful.


#12
  1. The abbreviation is standard on Unixes. This is the first thing an experienced user would look for.

  2. It is very well documented, both in Getting Started, and in the command line:

$ julia --help | grep juliarc
 --startup-file={yes|no}   Load ~/.juliarc.jl

#13

FYI it’s been moved to ~/.julia/config/startup.jl