xtask/commands/
rextendr_document.rs1use std::error::Error;
14
15use crate::extendrtests::with_absolute_path::{swap_extendr_api_path, R_FOLDER_PATH};
16use xshell::{cmd, Shell};
17
18pub(crate) fn run(shell: &Shell) -> Result<(), Box<dyn Error>> {
19 let _document_handle = swap_extendr_api_path(shell)?;
20
21 run_rextendr_document(shell)
22}
23
24fn run_rextendr_document(shell: &Shell) -> Result<(), Box<dyn Error>> {
25 let _r_path = shell.push_dir(R_FOLDER_PATH);
26
27 let rextendr_submodule = std::path::Path::new(".../../rextendr");
28 let rextendr_submodule = matches!(rextendr_submodule.try_exists(), Ok(true));
29 if rextendr_submodule {
30 println!("Loading vendored `{{rextendr}}`");
31 cmd!(shell, "Rscript")
32 .args([
33 "-e",
34 r#"requireNamespace("devtools")"#,
35 "-e",
36 r#"devtools::load_all("../../rextendr")"#,
37 "-e",
38 r#"rextendr::document()"#,
39 ])
40 .run()?;
41 } else {
42 println!("Using installed `{{rextendr}}`");
44 cmd!(shell, "Rscript")
45 .args([
46 "-e",
47 r#"requireNamespace("rextendr")"#,
48 "-e",
49 r#"rextendr::document()"#,
50 ])
51 .run()?;
52 }
53
54 Ok(())
55}