Packages

Robust statistics based on Statistex library

Current section

3 Versions

Jump to

Compare versions

3 files changed
+17 additions
-8 deletions
  @@ -1,7 +1,7 @@
1 1 {<<"links">>,
2 2 [{<<"GitHub">>,<<"https://github.com/chazzka/statistex_robust">>}]}.
3 3 {<<"name">>,<<"statistex_robust">>}.
4 - {<<"version">>,<<"0.1.1">>}.
4 + {<<"version">>,<<"0.1.2">>}.
5 5 {<<"description">>,<<"Robust statistics based on Statistex library">>}.
6 6 {<<"elixir">>,<<"~> 1.17">>}.
7 7 {<<"app">>,<<"statistex_robust">>}.
  @@ -14,5 +14,10 @@
14 14 {<<"app">>,<<"statistex">>},
15 15 {<<"optional">>,false},
16 16 {<<"requirement">>,<<"~> 1.0">>},
17 + {<<"repository">>,<<"hexpm">>}],
18 + [{<<"name">>,<<"briefly">>},
19 + {<<"app">>,<<"briefly">>},
20 + {<<"optional">>,false},
21 + {<<"requirement">>,<<"~> 0.3">>},
17 22 {<<"repository">>,<<"hexpm">>}]]}.
18 23 {<<"build_tools">>,[<<"mix">>]}.
  @@ -51,12 +51,16 @@ defmodule Statistex.Robust do
51 51 def medcouple(arr) do
52 52 args = arr |> Enum.map(&to_string/1)
53 53
54 - # Capture both stdout and stderr
54 + {:ok, r_script_path} = Briefly.create(extname: ".R")
55 + File.write!(r_script_path, r_script())
56 +
57 + {:ok, input_path} = Briefly.create(extname: ".txt")
58 + File.write!(input_path, Enum.join(args, "\n") <> "\n")
59 +
55 60 {result, exit_code} =
56 - System.cmd("Rscript", ["-e", r_script()] ++ args, stderr_to_stdout: true)
61 + System.cmd("Rscript", [r_script_path, input_path], stderr_to_stdout: true)
57 62
58 63 if exit_code != 0 do
59 - # Rscript ended with an error, handle it accordingly
60 64 {:error, "Rscript failed with exit code #{exit_code}: #{String.trim(result)}"}
61 65 else
62 66 String.trim(result) |> String.to_float()
  @@ -69,8 +73,8 @@ defmodule Statistex.Robust do
69 73 stop("The 'robustbase' package is required but not installed. Please install it using install.packages('robustbase').")
70 74 }
71 75 library(robustbase)
72 - args <- commandArgs(trailingOnly = TRUE)
73 - arr <- as.numeric(args)
76 + args_file <- commandArgs(trailingOnly = TRUE)[1]
77 + arr <- scan(args_file, what = numeric(), quiet = TRUE)
74 78 options(mc_doScale_quiet=TRUE)
75 79 result <- mc(arr)
76 80 cat(sprintf("%.10f", result))
  @@ -5,7 +5,7 @@ defmodule StatistexRobust.MixProject do
5 5 [
6 6 app: :statistex_robust,
7 7 description: "Robust statistics based on Statistex library",
8 - version: "0.1.1",
8 + version: "0.1.2",
9 9 elixir: "~> 1.17",
10 10 start_permanent: Mix.env() == :prod,
11 11 deps: deps(),
  @@ -44,7 +44,7 @@ defmodule StatistexRobust.MixProject do
44 44 defp deps do
45 45 [
46 46 {:statistex, "~> 1.0"},
47 -
47 + {:briefly, "~> 0.3"}, # temporary filesystem for large R inputs
48 48 # dependencies for `examples` env
49 49 {:nimble_csv, "~> 1.1", only: :example},
50 50 {:ex_doc, "~> 0.25", only: :dev, runtime: false}