Run Julia function every time Julia environment starts

I am moving from R and I use the head () function a lot . I couldn't find a similar method in Julia, so I wrote one for Julia Arrays. There are a couple of other R functions that I carry over to Julia.

I need these methods to be available for use in every instance of Julia that is run, whether via IJulia or via the command line. Is there a "startup script" for Julia? How can I achieve this?

PS: In case anyone is interested, this is what I wrote. A lot needs to be done for general use, but it does what I need it to do now.

function head(obj::Array; nrows=5, ncols=size(obj)[2])
     if (size(obj)[1] < nrows)
       println("WARNING: nrows is greater than actual number of rows in the obj Array.")
       nrows = size(obj)[1]
     end
     obj[[1:nrows], [1:ncols]]
   end

      

+2


source to share


1 answer


You can create a file ~/.juliarc.jl

, see the Getting Started section of the manual.

As a function for you head

, this is how I would do it:



function head(obj::Array; nrows=5, ncols=size(obj,2))
    if size(obj,1) < nrows
        warn("nrows is greater than actual number of rows in the obj Array.")
        nrows = size(obj,1)
    end
    obj[1:nrows, 1:ncols]
end

      

+6


source







All Articles