Skip to content

Commit

Permalink
include ahead::ridge2f
Browse files Browse the repository at this point in the history
  • Loading branch information
thierrymoudiki committed Jan 14, 2024
1 parent 974f46d commit 559bd9f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ WORKDIR /app
RUN apt-get update && apt-get install -y \
r-base \
r-base-dev
RUN Rscript -e "utils::install.packages('foreach', repos='https://cran.rstudio.com', dependencies=TRUE)"
RUN Rscript -e "utils::install.packages('Rcpp', repos='https://cran.rstudio.com', dependencies=TRUE)"
RUN Rscript -e "utils::install.packages('snow', repos='https://cran.rstudio.com', dependencies=TRUE)"
RUN Rscript -e "utils::install.packages('forecast', repos='https://cran.rstudio.com', dependencies=TRUE)"
RUN Rscript -e "utils::install.packages('ahead', repos='https://techtonique.r-universe.dev', dependencies=TRUE)"
RUN Rscript -e "install_foreach <- try(utils::install.packages('foreach', repos='https://cran.rstudio.com', dependencies=TRUE), silent=TRUE)"
RUN Rscript -e "install_rcpp <- try(utils::install.packages('Rcpp', repos='https://cran.rstudio.com', dependencies=TRUE), silent=TRUE)"
RUN Rscript -e "install_snow <- try(utils::install.packages('snow', repos='https://cran.rstudio.com', dependencies=TRUE), silent=TRUE)"
RUN Rscript -e "install_forecast <- try(utils::install.packages('forecast', repos='https://cran.rstudio.com', dependencies=TRUE), silent=TRUE)"
RUN Rscript -e "install_forecast <- try(utils::install.packages('randtoolbox', repos='https://cran.rstudio.com', dependencies=TRUE), silent=TRUE)"
RUN Rscript -e "install_forecast <- try(utils::install.packages('VineCopula', repos='https://cran.rstudio.com', dependencies=TRUE), silent=TRUE)"
RUN Rscript -e "install_ahead <- try(utils::install.packages('ahead', repos='https://techtonique.r-universe.dev', dependencies=TRUE), silent=TRUE)"

# Copy all files from the current directory to /app in the container
COPY . .
Expand Down
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ authors = ["thierrymoudiki <[email protected]>"]
version = "0.1.0"

[compat]
Distributions = "0.25.107"
julia = "1.10"
Pkg = "1.6.7"
RCall = "0.14.0"

[deps]
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
RCall = "6f49c342-dc21-5d91-9882-a32aef131414"

[extras]
Expand Down
13 changes: 11 additions & 2 deletions src/Ahead.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Ahead

# exports
export dynrmf
export ridge2f

if Sys.islinux()
try
Expand Down Expand Up @@ -48,13 +49,17 @@ module Ahead
run(`sudo Rscript -e "utils::install.packages('Rcpp', repos='https://cran.rstudio.com', dependencies=TRUE)"`)
run(`sudo Rscript -e "utils::install.packages('snow', repos='https://cran.rstudio.com', dependencies=TRUE)"`)
run(`sudo Rscript -e "utils::install.packages('forecast', repos='https://cran.rstudio.com', dependencies=TRUE)"`)
run(`sudo Rscript -e "utils::install.packages('randtoolbox', repos='https://cran.rstudio.com', dependencies=TRUE)"`)
run(`sudo Rscript -e "utils::install.packages('VineCopula', repos='https://cran.rstudio.com', dependencies=TRUE)"`)
run(`sudo Rscript -e "utils::install.packages('ahead', repos='https://techtonique.r-universe.dev', dependencies=TRUE)"`)
catch e1
try
run(`sudo Rscript -e "install.packages('foreach', repos='https://cran.rstudio.com', lib= '.', dependencies=TRUE)"`)
run(`sudo Rscript -e "install.packages('Rcpp', repos='https://cran.rstudio.com', lib= '.', dependencies=TRUE)"`)
run(`sudo Rscript -e "install.packages('snow', repos='https://cran.rstudio.com', lib= '.', dependencies=TRUE)"`)
run(`sudo Rscript -e "install.packages('forecast', repos='https://cran.rstudio.com', lib= '.', dependencies=TRUE)"`)
run(`sudo Rscript -e "install.packages('randtoolbox', repos='https://cran.rstudio.com', lib= '.', dependencies=TRUE)"`)
run(`sudo Rscript -e "install.packages('VineCopula', repos='https://cran.rstudio.com', lib= '.', dependencies=TRUE)"`)
run(`sudo Rscript -e "utils::install.packages('ahead', repos='https://techtonique.r-universe.dev', lib= '.', dependencies=TRUE)"`)
catch e2
println("Can't run Rscript")
Expand All @@ -64,11 +69,15 @@ module Ahead
end
end

R"load_ahead <- try(library(ahead), silent = TRUE)"
R"load_ahead <- try(library(ahead), silent = TRUE)"
R"if(inherits(load_ahead, 'try-error')) {library(ahead, lib.loc='.')}"

function dynrmf(y, h)
return rcopy(R"try(ahead::dynrmf($y, $h), silent = TRUE)")
return rcopy(R"try(ahead::dynrmf(y=$y, h=$h), silent = TRUE)")
end

function ridge2f(y, h)
return rcopy(R"try(ahead::ridge2f(y=$y, h=$h), silent = TRUE)")
end
end

12 changes: 11 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
using Ahead
using Distributions
using Random
using Test

@testset "Ahead.jl" begin
val = Ahead.dynrmf([1,2,3,4,5,6,7,8,9,10], 6)

val = Ahead.dynrmf([1,2,3,4,5,6,7,8,9,10], 6)
println(val)
@test isapprox(round(val[:residuals][1]), 0)

rng = MersenneTwister(1234);
y = randexp(rng, 10, 3)
val = Ahead.ridge2f(y, 6)
println(val)
@test val[:x] == y

end

0 comments on commit 559bd9f

Please sign in to comment.