<commit_before>#!/usr/bin/env bash

koopa::macos_install_r_cran_clang() { # {{{1
    # """
    # Install CRAN clang.
    # @note Updated 2020-07-30.
    # Only needed for R < 4.0.
    # """
    local file major_version name prefix reinstall tmp_dir url version
    while (("$#"))
    do
        case "$1" in
            --reinstall)
                reinstall=1
                shift 1
                ;;
            --version=*)
                version="${1#*=}"
                shift 1
                ;;
            *)
                koopa::invalid_arg "$1"
                ;;
        esac
    done
    koopa::assert_has_no_args "$#"
    name='clang'
    major_version="$(koopa::major_version "$version")"
    prefix="/usr/local/${name}${major_version}"
    [[ "$reinstall" -eq 1 ]] && koopa::rm -S "$prefix"
    [[ -d "$prefix" ]] && return 0
    koopa::h1 "Installing ${name} ${version} to '${prefix}'."
    tmp_dir="$(koopa::tmp_dir)"
    (
        koopa::cd "$tmp_dir"
        file="${name}-${version}.pkg"
        url="https://cran.r-project.org/bin/macosx/tools/${file}"
        koopa::download "$url"
        sudo installer -pkg "$file" -target '/'
    ) 2>&1 | tee "$(koopa::tmp_log_file)"
    koopa::rm "$tmp_dir"
    koopa::install_success "$name"
    koopa::alert_restart
    return 0
}

koopa::macos_install_r_cran_clang_7() { # {{{1
    koopa::macos_install_r_cran_clang --version='7.0.0'
    return 0
}

koopa::macos_install_r_cran_clang_8() { # {{{1
    koopa::macos_install_r_cran_clang --version='8.0.0'
    return 0
}

koopa::macos_install_r_cran_gfortran() { # {{{1
    # """
    # Install CRAN gfortran.
    # @note Updated 2020-07-17.
    # @seealso
    # - https://github.com/fxcoudert/gfortran-for-macOS
    # """
    local file name pkg prefix reinstall stem tmp_dir url version
    reinstall=0
    while (("$#"))
    do
        case "$1" in
            --reinstall)
                reinstall=1
                shift 1
                ;;
            --version=*)
                version="${1#*=}"
                shift 1
                ;;
            *)
                koopa::invalid_arg "$1"
                ;;
        esac
    done
    koopa::assert_has_no_args "$#"
    name='gfortran'
    prefix="/usr/local/${name}"
    [[ "$reinstall" -eq 1 ]] && koopa::rm -S "$prefix"
    [[ -d "$prefix" ]] && return 0
    koopa::h1 "Installing ${name} ${version} to '${prefix}'."
    tmp_dir="$(koopa::tmp_dir)"
    (
        koopa::cd "$tmp_dir"
        # This is compatible with Catalina.
        stem="${name}-${version}-Mojave"
        file="${stem}.dmg"
        url="https://mac.r-project.org/tools/${file}"
        koopa::download "$url"
        hdiutil mount "$file"
        pkg="/Volumes/${stem}/${stem}/gfortran.pkg"
        sudo installer -pkg "$pkg" -target /
        hdiutil unmount "/Volumes/${stem}"
    ) 2>&1 | tee "$(koopa::tmp_log_file)"
    koopa::rm "$tmp_dir"
    koopa::install_success "$name"
    koopa::alert_restart
    return 0
}

koopa::macos_install_r_cran_gfortran_8() { # {{{1
    koopa::macos_install_r_cran_gfortran --version='6.1'
    return 0
}

koopa::macos_install_r_cran_gfortran_8() { # {{{1
    koopa::macos_install_r_cran_gfortran --version='8.2'
    return 0
}

koopa::macos_install_r_devel() { # {{{1
    # """
    # Install R-devel on macOS.
    # @note Updated 2021-03-25.
    # """
    local arch file macos_version name_fancy r_version tmp_dir url
    koopa::assert_has_no_args "$#"
    arch="$(koopa::arch)"
    r_version='devel'
    macos_version='el-capitan'<commit_msg>Draft update<commit_after>#!/usr/bin/env bash

# FIXME MAKE THIS MORE GENERAL AND JUST REQUIRE THE VERSION HERE...
koopa::macos_install_r_cran_clang() { # {{{1
    # """
    # Install CRAN clang.
    # @note Updated 2020-07-30.
    # Only needed for R < 4.0.
    # """
    local file major_version name prefix reinstall tmp_dir url version
    while (("$#"))
    do
        case "$1" in
            --reinstall)
                reinstall=1
                shift 1
                ;;
            --version=*)
                version="${1#*=}"
                shift 1
                ;;
            *)
                koopa::invalid_arg "$1"
                ;;
        esac
    done
    koopa::assert_is_set version
    koopa::assert_has_no_args "$#"
    name='clang'
    major_version="$(koopa::major_version "$version")"
    prefix="/usr/local/${name}${major_version}"
    [[ "$reinstall" -eq 1 ]] && koopa::rm -S "$prefix"
    [[ -d "$prefix" ]] && return 0
    koopa::h1 "Installing ${name} ${version} to '${prefix}'."
    tmp_dir="$(koopa::tmp_dir)"
    (
        koopa::cd "$tmp_dir"
        file="${name}-${version}.pkg"
        url="https://cran.r-project.org/bin/macosx/tools/${file}"
        koopa::download "$url"
        sudo installer -pkg "$file" -target '/'
    ) 2>&1 | tee "$(koopa::tmp_log_file)"
    koopa::rm "$tmp_dir"
    koopa::install_success "$name"
    koopa::alert_restart
    return 0
}

# FIXME MAKE THIS SUPPORTED FLAGS ABOVE.
koopa::macos_install_r_cran_clang_7() { # {{{1
    koopa::macos_install_r_cran_clang --version='7.0.0'
    return 0
}

# FIXME MAKE THIS SUPPORTED FLAGS ABOVE.
koopa::macos_install_r_cran_clang_8() { # {{{1
    koopa::macos_install_r_cran_clang --version='8.0.0'
    return 0
}

# FIXME MATCH THIS TO THE R VERSION INSTEAD.
# FIXME NEED TO RETHINK THE VERSION HANDLING HERE.
koopa::macos_install_r_cran_gfortran() { # {{{1
    # """
    # Install CRAN gfortran.
    # @note Updated 2021-04-22.
    # @seealso
    # - https://github.com/fxcoudert/gfortran-for-macOS
    # """
    local file name pkg prefix reinstall stem tmp_dir url version
    reinstall=0
    while (("$#"))
    do
        case "$1" in
            --reinstall)
                reinstall=1
                shift 1
                ;;
            --version=*)
                version="${1#*=}"
                shift 1
                ;;
            *)
                koopa::invalid_arg "$1"
                ;;
        esac
    done
    koopa::assert_has_no_args "$#"
    name='gfortran'
    prefix="/usr/local/${name}"
    [[ "$reinstall" -eq 1 ]] && koopa::rm -S "$prefix"
    [[ -d "$prefix" ]] && return 0
    # FIXME THIS IS NOW RETURNING AN UNBOUND VARIABLE.
    koopa::h1 "Installing ${name} ${version} to '${prefix}'."
    tmp_dir="$(koopa::tmp_dir)"
    (
        koopa::cd "$tmp_dir"
        # This is compatible with Catalina.
        stem="${name}-${version}-Mojave"
        file="${stem}.dmg"
        url="https://mac.r-project.org/tools/${file}"
        koopa::download "$url"
        hdiutil mount "$file"
        pkg="/Volumes/${stem}/${stem}/gfortran.pkg"
        sudo installer -pkg "$pkg" -target /
        hdiutil unmount "/Volumes/${stem}"
    ) 2>&1 | tee "$(koopa::tmp_log_file)"
    koopa::rm "$tmp_dir"
    koopa::install_success "$name"
    koopa::alert_restart
    return 0
}

# FIXME TAKE THESE OUT AND MATCH TO THE R VERSION INSTEAD...
koopa::macos_install_r_cran_gfortran_6() { # {{{1
    koopa::macos_install_r_cran_gfortran --version='6.1'
    return 0
}

koopa::macos_install_r_cran_gfortran_8() { # {{{1
    koopa::macos_install_r_cran_gfortran --version='8.2'
    return 0
}

koopa::macos_install_r_devel() { # {{{1
    # """
    # Install R-devel on macOS.
    # @note Updated 2021-03-25.
    # """
    local arch file macos_version name_fancy r_version tmp_dir url
    koopa::assert_has_no_args "$#"
    arch="$(koopa::arch)"
    r_version='devel'
    macos_version='el-capitan'
{'fraction_non_alphanumeric': 0.16211878009630817, 'fraction_numerical': 0.020331728196896735, 'mean_word_length': 2.162859560067682, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6195080', 'n_tokens_mistral': 2865, 'n_tokens_neox': 2629, 'n_words': 502}