每当Julia环境启动时运行Julia函数 [英] Run Julia function every time Julia environment launches

查看:54
本文介绍了每当Julia环境启动时运行Julia函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要从R搬出,并且使用 head()函数很多.我在Julia中找不到类似的方法,所以我为Julia Arrays写了一个方法.我还将其他两个R函数移植到Julia中.

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 couple other R functions that I'm porting to Julia as well.

无论是通过IJulia还是通过命令行,我都需要这些方法可用于每个启动的Julia实例.朱莉娅有某种启动脚本"吗?我怎样才能做到这一点?

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

PS:如果有人感兴趣,这就是我写的.通用用途需要做很多工作,但是它确实满足了我目前的需要.

PS: In case someone else is interested, this is what I wrote. A lot needs to be done for general-purpose use, but it does what I need it to for 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

推荐答案

您可以制作一个~/.juliarc.jl文件,请参见

You can make a ~/.juliarc.jl file, see the Getting Started section of the manual.

对于您的head函数,这是我的处理方式:

As for you head function, here is how I'd 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

这篇关于每当Julia环境启动时运行Julia函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆