Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test with respect to R code #3

Merged
merged 15 commits into from
Apr 5, 2024
30 changes: 30 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -32,13 +32,29 @@ jobs:
- x64
steps:
- uses: actions/checkout@v4
- uses: r-lib/actions/setup-r@v2
with:
r-version: '4.2.1'
- name: Install R packages survival & relsurv
uses: r-lib/actions/setup-r-dependencies@v2
with:
packages: |
any::survival
any::relsurv
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
env:
R_HOME: "/opt/R/4.2.1/lib/R"
LD_LIBRARY_PATH: /opt/R/4.2.1/lib/R/lib
- uses: julia-actions/julia-processcoverage@v1
- uses: julia-actions/julia-runtest@v1
env:
R_HOME: "/opt/R/4.2.1/lib/R"
LD_LIBRARY_PATH: /opt/R/4.2.1/lib/R/lib
docs:
name: Documentation
runs-on: ubuntu-latest
@@ -48,6 +64,15 @@ jobs:
statuses: write
steps:
- uses: actions/checkout@v4
- uses: r-lib/actions/setup-r@v2
with:
r-version: '4.2.1'
- name: Install R packages survival & relsurv
uses: r-lib/actions/setup-r-dependencies@v2
with:
packages: |
any::survival
any::relsurv
- uses: julia-actions/setup-julia@v1
with:
version: '1'
@@ -59,8 +84,13 @@ jobs:
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()
- uses: julia-actions/julia-buildpkg@v1
env:
R_HOME: "/opt/R/4.2.1/lib/R"
LD_LIBRARY_PATH: /opt/R/4.2.1/lib/R/lib
- uses: julia-actions/julia-docdeploy@v1
env:
R_HOME: "/opt/R/4.2.1/lib/R"
LD_LIBRARY_PATH: /opt/R/4.2.1/lib/R/lib
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
- name: Run doctests
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -24,10 +24,12 @@ Tables = "1"
Test = "1.6"
TestItemRunner = "0.2"
julia = "1.9"
RCall = "0.14"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
RCall = "6f49c342-dc21-5d91-9882-a32aef131414"

[targets]
test = ["Test", "TestItemRunner"]
test = ["Test", "TestItemRunner", "RCall"]
37 changes: 36 additions & 1 deletion test/sampletest.jl
Original file line number Diff line number Diff line change
@@ -21,5 +21,40 @@ end
@test true

# How to use R and R packages in here ?

end


@testitem "trying RCall" begin

# R version
using RCall
R"""
rez = relsurv::rs.surv(
survival::Surv(time, stat) ~1,
rmap=list(age = age, sex = sex, year = diag),
data = relsurv::colrec,
ratetable = relsurv::slopop,
method = "pohar-perme",
add.times=1:8149)
"""
R_model = @rget rez
R_grid = R_model[:time]
R_Sₑ = R_model[:surv]
R_σ = R_model[:std_err]
R_low = R_model[:lower]
R_upp = R_model[:upper]


# Julia version
instance = PoharPerme(colrec.time, colrec.status, colrec.age, colrec.year, colrec.sex, slopop)
conf_int = confint(instance; level = 0.05)
lower_bounds = [lower[1] for lower in conf_int]
upper_bounds = [upper[2] for upper in conf_int]

err_S = (R_Sₑ .- instance.Sₑ[1:end-1]) ./ R_Sₑ
err_σ = (R_σ .- instance.σₑ[1:end-1]) ./ R_σ

@test all(abs.(err_S) .<= 0.01)
@test all(abs.(err_σ) .<= 0.01)

end
Loading