|
| 1 | +# This script was copied and modified from the source code of the {instantiate} |
| 2 | +# R package by William Michael Landau. License and copyright are in the comment below. |
| 3 | +# |
| 4 | +# MIT License |
| 5 | +# ===================== |
| 6 | +# |
| 7 | +# Copyright 2023 Eli Lilly and Company |
| 8 | +# |
| 9 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 10 | +# of this software and associated documentation files (the “Software”), to deal |
| 11 | +# in the Software without restriction, including without limitation the rights |
| 12 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 13 | +# copies of the Software, and to permit persons to whom the Software is |
| 14 | +# furnished to do so, subject to the following conditions: |
| 15 | +# |
| 16 | +# The above copyright notice and this permission notice shall be included |
| 17 | +# in all copies or substantial portions of the Software. |
| 18 | +# |
| 19 | +# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 20 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 24 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 25 | +# THE SOFTWARE. |
| 26 | +libs <- file.path(R_PACKAGE_DIR, "libs", R_ARCH) |
| 27 | +dir.create(libs, recursive = TRUE, showWarnings = FALSE) |
| 28 | +for (file in c("symbols.rds", Sys.glob(paste0("*", SHLIB_EXT)))) { |
| 29 | + if (file.exists(file)) { |
| 30 | + file.copy(file, file.path(libs, file)) |
| 31 | + } |
| 32 | +} |
| 33 | +inst_stan <- file.path("..", "inst", "stan") |
| 34 | +if (dir.exists(inst_stan)) { |
| 35 | + warning( |
| 36 | + "Stan models in inst/stan/ are deprecated in {instantiate} ", |
| 37 | + ">= 0.0.4.9001 (2024-01-03). Please put them in src/stan/ instead." |
| 38 | + ) |
| 39 | + if (file.exists("stan")) { |
| 40 | + warning("src/stan/ already exists. Not copying models from inst/stan/.") |
| 41 | + } else { |
| 42 | + message("Copying inst/stan/ to src/stan/.") |
| 43 | + fs::dir_copy(path = inst_stan, new_path = "stan") |
| 44 | + } |
| 45 | +} |
| 46 | +bin <- file.path(R_PACKAGE_DIR, "bin") |
| 47 | +if (!file.exists(bin)) { |
| 48 | + dir.create(bin, recursive = TRUE, showWarnings = FALSE) |
| 49 | +} |
| 50 | +bin_stan <- file.path(bin, "stan") |
| 51 | +fs::dir_copy(path = "stan", new_path = bin_stan) |
| 52 | +callr::r( |
| 53 | + func = function(bin_stan) { |
| 54 | + instantiate::stan_package_compile( |
| 55 | + models = instantiate::stan_package_model_files(path = bin_stan) |
| 56 | + ) |
| 57 | + }, |
| 58 | + args = list(bin_stan = bin_stan) |
| 59 | +) |
0 commit comments