Skip to main content
Chemistry LibreTexts

5.2.2: How to Incorporate Data Files in Your Code Blocks- For Julia

  • Page ID
    216018
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    There are a number of ways data files and can be incorporated into code blocks. However, ensure that you have already followed the steps in the introduction to the CKEditor Binder Plugin Tutorial here.

    Method 1: Using Julia Packages

    Simply replace the URL of your data file in the below example code block to load your data in.

    import Pkg; Pkg.add("HTTP")
    
    import Pkg; Pkg.add("DelimitedFiles")
    
    using HTTP
    using DelimitedFiles
    data = HTTP.get("https://chem.libretexts.org/@api/deki/files/265970/auto-mpg.data")
    
    myCSV = readdlm(data.body)

    Method 2: Using wget or other shell commands

    The second method that can be used to get a data file in your code block is with wget.. Note that the command is contained in backticks, not normal single quotes. Shell commands will not work with normal single quotes. Follow the example below and replace the example URL with the one attained in the previous step. Once the file is loaded, read and utilize it just as you would on your local computer.

    run(`wget https://chem.libretexts.org/@api/deki/files/265970/auto-mpg.data`)

    Note: using the run command allows the user to run any shell command in Julia


    5.2.2: How to Incorporate Data Files in Your Code Blocks- For Julia is shared under a CC BY 1.3 license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?