SeeminglyArbitrary minimal but not meaningless

How to create your own package in Julia

In this post, I will show you how to create your own Julia package in just a few easy steps. I have found the Julia programming language about a year ago and since then I am a huge fan. My thesis required a lot of time-consuming Monte Carlo simulations and originally the code was written in MatLab and it was just fine to finish my thesis but I still have plans to publish the study at some point. To achieve that goal I needed a more scalable solution, not just a simple script.

My first idea was to re-implement everything in Python, however, I quickly realized that Python was not much faster and the way how NumPy handles matrices and vectors is just not for me. I always try to keep an open eye on exciting programming languages and when I heard that there is one out there that combines features from MatLab and Python and it is said to be super fast, I had to look into it. In my opinion, Julia has its issues and for most of my work I am still using Python as default, however, to implement my MCMC simulation-based models, Julia is just a really good choice. As my codebase grew, I started thinking about how could I convert it to a proper package type of project, and as it turned out, it is quite easy, you just have to follow these steps:

  1. Open up Julia in terminal
  2. Navigate to the location where you want to create your package (cd("..") and pwd() help)
  3. Type ], this activates the Julia Package Manager
  4. Run generate YourPackageName to generate your package
  5. Run cd("YourPackageName")
  6. Type ] and run activate ., this will activate your package. Now the package is ready to use, but if you want to import other packages within your project, you have to add those by ] and add OtherPackages (eg Distributions, LinearAlgebra, etc.)
  7. import the package and run your implemented functions

generate_package

Tips and tricks, and some additional info:

Useful resources: