Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit c2735f5
Author: Dan Dediu <ddediu@gmail.com>
Date:   Tue Jul 5 17:37:50 2022 +0200

    Bugfix 0.8.1

commit c3964db
Author: Dan Dediu <ddediu@gmail.com>
Date:   Mon Jun 27 13:28:30 2022 +0200

    Fix CMA_polypharmacy() crash in 0.8.0

commit a856c89
Author: Dan Dediu <ddediu@gmail.com>
Date:   Sat Jun 25 11:55:09 2022 +0200

    Julia: check that RCall, R and AdhereR/AdhereRViz are installed and work

commit 47a5f2b
Author: Dan Dediu <ddediu@gmail.com>
Date:   Fri Jun 24 20:58:33 2022 +0200

    Bump version to 0.8.1

commit 9b33030
Author: Dan Dediu <ddediu@gmail.com>
Date:   Fri Jun 24 20:56:41 2022 +0200

    Starting to work on the Julia bridge

commit 5c1d4f9
Author: Dan Dediu <ddediu@gmail.com>
Date:   Fri Jun 24 17:39:41 2022 +0200

    As submitted to CRAN

commit fdeb7d8
Author: Dan Dediu <ddediu@gmail.com>
Date:   Sat Jun 18 20:33:35 2022 +0200

    Fix CRAN check errors and warnings

commit a6d8423
Author: Dan Dediu <ddediu@gmail.com>
Date:   Fri Jun 17 16:43:49 2022 +0200

    Solve GitHub #190 by allowing the recovery of the mapping between events and episodes/sliding windows, and even plotting it

commit 5a74ae9
Author: Dan Dediu <ddediu@gmail.com>
Date:   Fri Jun 17 12:42:44 2022 +0200

    Implement return.mapping.events.sliding.window for CMA_sliding_window

commit 7768564
Author: Dan Dediu <ddediu@gmail.com>
Date:   Fri Jun 17 11:33:07 2022 +0200

    Fix GitHub #192: now  align.first.event.at.zero is FALSE by default

commit f0f3b5d
Author: Dan Dediu <ddediu@gmail.com>
Date:   Thu Jun 16 23:39:57 2022 +0200

    The simple CMAs return .EVENT.USED.IN.CMA in event.info

commit 9b5975a
Author: Dan Dediu <ddediu@gmail.com>
Date:   Wed Jun 15 16:28:13 2022 +0200

    Fix GitHub #191 and bump version to 0.8

commit 3cac87b
Author: Dan Dediu <ddediu@gmail.com>
Date:   Mon Jun 6 16:46:45 2022 +0200

    Fix GitHub #184: Python 3 wrapper does not show anymore warnings about overriding some arguments

commit 85475b1
Author: Dan Dediu <ddediu@gmail.com>
Date:   Mon Jun 6 16:15:44 2022 +0200

    Python3 wrapper: handle plotting complex CMAs with event intervals

commit 2880088
Author: Dan Dediu <ddediu@gmail.com>
Date:   Mon Jun 6 16:14:31 2022 +0200

    Fix bug when plotting complex CMAs showing event intervals with custom column names

commit 37c25c7
Author: Dan Dediu <ddediu@gmail.com>
Date:   Tue May 31 18:13:47 2022 +0200

    Update the NEWS.md to reflect the Python 3 changes

commit 58d2b7d
Author: Dan Dediu <ddediu@gmail.com>
Date:   Tue May 31 18:11:18 2022 +0200

    Rebuild the Python3 vignette (and remove the junyper checkpoint)

commit 6c4a539
Author: Dan Dediu <ddediu@gmail.com>
Date:   Tue May 31 18:07:55 2022 +0200

    AdhereR works from Python 3 Jupyter Notebooks (and with rpy2)!

    I also update the vignette and added two notebook examples

commit bc77b21
Author: Dan Dediu <ddediu@gmail.com>
Date:   Tue May 31 15:06:44 2022 +0200

    Fix GitHub #184 and a bug with Python3 and plotting complex CMAs

commit 675d57a
Author: Dan Dediu <ddediu@gmail.com>
Date:   Tue May 31 14:05:24 2022 +0200

    Pyhton3 wrapper: handle medication groups (defined by a column in the data)

commit 17d6b22
Author: Dan Dediu <ddediu@gmail.com>
Date:   Tue May 31 11:29:49 2022 +0200

    Python 3 wrapper: finished updating plot() + small bug fixes

commit 8d5d13e
Author: Dan Dediu <ddediu@gmail.com>
Date:   Mon May 30 16:51:35 2022 +0200

    Python3 wrapper: add plot.partial.CMAs* to plot()

commit bac9449
Author: Dan Dediu <ddediu@gmail.com>
Date:   Mon May 30 13:43:37 2022 +0200

    Python3 wrapper: add CMA.cex to plot()

commit 9ed89d2
Author: Dan Dediu <ddediu@gmail.com>
Date:   Mon May 30 11:51:04 2022 +0200

    Python3 wrapper: add dose* to plot()

commit e641baa
Author: Dan Dediu <ddediu@gmail.com>
Date:   Mon May 30 10:52:01 2022 +0200

    Python3 wrapper: implemented medication.groups in plot()

commit a135ce3
Author: Dan Dediu <ddediu@gmail.com>
Date:   Fri May 27 19:31:06 2022 +0200

    Python3 wrapper: xlab, ylab & title added to plot()

commit 69e6575
Author: Dan Dediu <ddediu@gmail.com>
Date:   Fri May 27 12:54:08 2022 +0200

    Python3 wrapper: make col.cats in plot() work

commit be1a454
Author: Dan Dediu <ddediu@gmail.com>
Date:   Fri May 27 11:32:19 2022 +0200

    Fix bug: cex.title in plot() was not implemented

commit e1b5b65
Author: Dan Dediu <ddediu@gmail.com>
Date:   Fri May 27 11:08:08 2022 +0200

    Starting to update the Python3 wrapper to reflect the new parameters

commit c2ddb1a
Author: Dan Dediu <ddediu@gmail.com>
Date:   Wed May 25 17:05:02 2022 +0200

    Fix GitHub #182: the vignette shows how to change an AdhereR plot

commit b19e6bd
Author: Dan Dediu <ddediu@gmail.com>
Date:   Mon May 23 22:10:25 2022 +0200

    Fixes issue #181 (plotting with aligned patients) and shows how to use AdhereR with pipe

commit 05d02b4
Author: Dan Dediu <ddediu@gmail.com>
Date:   Thu May 19 19:21:46 2022 +0200

    Latest source packages AdhereR 0.7.1 and bump to AdhereRViz 0.2.1

commit 79a966f
Author: Dan Dediu <ddediu@gmail.com>
Date:   Thu May 19 19:19:16 2022 +0200

    Work-around for GitHub #156 by allowing the plotting of the legend only

commit 9e5a311
Author: Dan Dediu <ddediu@gmail.com>
Date:   Thu May 19 12:35:57 2022 +0200

    Fix #169 by forcing arguments.that.should.not.be.defined=NULL (smartly) in sliding windows and per episodes

commit 42a3a82
Author: Dan Dediu <ddediu@gmail.com>
Date:   Thu May 19 11:59:10 2022 +0200

    Shiny: make sure the event interval defaults are correctly reset on changing the CMA

commit cf985f3
Author: Dan Dediu <ddediu@gmail.com>
Date:   Thu May 19 11:51:36 2022 +0200

    Fix #179 (CMA class not correctly initialised/updated in Shiny)

commit 9348b76
Author: Dan Dediu <ddediu@gmail.com>
Date:   Wed May 18 19:19:00 2022 +0200

    Shiny UI allows plotting event intervals for sliding windows and per per episodes

    Controlled from Aesthetics -> Event intervals; default = FALSE

commit 6e28af7
Author: Dan Dediu <ddediu@gmail.com>
Date:   Wed May 18 16:22:25 2022 +0200

    AdhererViz: bump version and fix check warnings

commit e4f5d36
Author: Dan Dediu <ddediu@gmail.com>
Date:   Wed May 18 13:09:18 2022 +0200

    Fixes GitHub issue #172

commit af2443c
Author: Dan Dediu <ddediu@gmail.com>
Date:   Wed May 18 13:05:10 2022 +0200

    Per episodes can also show the event intervals and gaps

commit ae58093
Author: Dan Dediu <ddediu@gmail.com>
Date:   Tue May 17 14:44:20 2022 +0200

    Update documentation and fix check warnings

commit 24eb65e
Author: Dan Dediu <ddediu@gmail.com>
Date:   Tue May 17 14:27:27 2022 +0200

    Plotting events and gaps seems to work for sliding windows

commit a51e0b1
Author: Dan Dediu <ddediu@gmail.com>
Date:   Fri May 13 13:25:32 2022 +0200

    Plotting intervals and gaps for sliding windows seems to work (but needs testing)

commit 95facec
Author: Dan Dediu <ddediu@gmail.com>
Date:   Fri May 13 11:14:48 2022 +0200

    ... actually, it does make sense to compute the inner.event.info even for overlapping windows (it is the user's problem to use them or not)

commit 9426ed5
Author: Dan Dediu <ddediu@gmail.com>
Date:   Fri May 13 11:06:24 2022 +0200

    Don't compute the inner.event.info if the sliding windows are overlapping

commit f3ac228
Author: Dan Dediu <ddediu@gmail.com>
Date:   Fri May 13 10:22:04 2022 +0200

    Don't print inner.event.info if present for per_episode and sliding_window objects

commit f0c6a68
Author: Dan Dediu <ddediu@gmail.com>
Date:   Tue Apr 5 19:57:25 2022 +0200

    Now plot() respects the order of patients given through patients.to.plot

commit f8cfb67
Author: Dan Dediu <ddediu@gmail.com>
Date:   Wed Nov 24 17:31:12 2021 +0100

    GitHub #172 : initial plotting of inner event intervals

commit 049760a
Author: Dan Dediu <ddediu@gmail.com>
Date:   Wed Nov 24 16:56:02 2021 +0100

    Fix GitHub #175

    + some other preliminary work on plotting event intervals in sliding windows and per intervals (but nothing user-visible yet)

commit ac22abe
Author: Dan Dediu <ddediu@gmail.com>
Date:   Mon Nov 22 12:44:14 2021 +0100

    Fix GitHub #174 (plus a small bug fix when plotting as a time series with 1 point)

    Now the placeholder for partial CMAs is plotted even if they don't have one...

commit 6c9846e
Author: Dan Dediu <ddediu@gmail.com>
Date:   Sun Nov 7 23:56:53 2021 +0100

    GitHub #172

    Proof-of-concept that I can return the full event.info from sliding windows -> it adds overheads so disabled by default, but can be enabled by forcing the new argument return.inner.event.info to TRUE
  • Loading branch information
ddediu committed Jul 6, 2022
1 parent 6d4955e commit 61b5be5
Show file tree
Hide file tree
Showing 8 changed files with 480 additions and 28 deletions.
2 changes: 1 addition & 1 deletion AdhereR/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: AdhereR
Type: Package
Title: Adherence to Medications
Version: 0.8.0
Version: 0.8.1
Authors@R: c(person("Dan", "Dediu", role = c("aut", "cre"),
email = "ddediu@gmail.com"),
person("Alexandra", "Dima", role = "aut",
Expand Down
8 changes: 7 additions & 1 deletion AdhereR/NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# AdhereR 0.7.1
# AdhereR 0.8.1

## Bug fixes

- fix `CMA_polypharmacy()` crash due to not properly handling the new internal `suppress.special.argument.checks` argument (now there's also a unit test for `CMA_polypharmacy` to avoid such bugs in the future).

# AdhereR 0.8.0

## New features

Expand Down
26 changes: 17 additions & 9 deletions AdhereR/R/polypharmacy.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ globalVariables(c(".PATIENT.MED.ID", ".new.ID", ".obs.duration", "EVENT.ID", "ID
#' \code{snow} for details).
#' @param suppress.warnings \emph{Logical}, if \code{TRUE} don't show any
#' warnings.
#' @param suppress.special.argument.checks \emph{Logical} parameter for internal
#' use; if \code{FALSE} (default) check if the important columns in the \code{data}
#' have some of the reserved names, if \code{TRUE} this check is not performed.
#' @param ... other possible parameters
#' @return An \code{S3} object of class \code{CMA_polypharmacy} with the
#' following fields:
Expand Down Expand Up @@ -260,6 +263,7 @@ CMA_polypharmacy <- function(data = data,
parallel.threads="auto", # specification (or number) of parallel threads
# Misc:
suppress.warnings=FALSE,
suppress.special.argument.checks=TRUE, # used internally to suppress the check that we don't use special argument names
...){

# Get the CMA function corresponding to the name:
Expand Down Expand Up @@ -369,7 +373,8 @@ CMA_polypharmacy <- function(data = data,
observation.window.duration=NULL,
observation.window.duration.unit=NULL,
date.format=NULL,
suppress.warnings=NULL
suppress.warnings=NULL,
suppress.special.argument.checks=NULL
)
{
# auxiliary function to compute intersection of episodes (when aggregate.first = TRUE)
Expand Down Expand Up @@ -487,7 +492,8 @@ CMA_polypharmacy <- function(data = data,
observation.window.duration=observation.window.duration.2,
observation.window.duration.unit=observation.window.duration.unit.2,
carry.only.for.same.medication=carry.only.for.same.medication,
date.format=date.format,parallel.backend="none")
date.format=date.format,parallel.backend="none",
suppress.special.argument.checks=suppress.special.argument.checks)

# get CMA values
CMA_per_group <- as.data.table(getCMA(CMA_all_by_group))
Expand Down Expand Up @@ -517,7 +523,7 @@ CMA_polypharmacy <- function(data = data,
# event_info <- rbindlist(event_info)

# merge back original ID and group and sort by original ID
setkeyv(event_info, "PATIENT_ID")
# setkeyv(event_info, "PATIENT_ID") # <- DD: I think this is an error, as there's no PATIENT_ID column in this event_info (as it uses ID.colname.2 as patient ID)...

# aggregate CMAs

Expand Down Expand Up @@ -577,7 +583,8 @@ CMA_polypharmacy <- function(data = data,
carry.only.for.same.medication = carry.only.for.same.medication,
date.format=date.format,
force.NA.CMA.for.failed.patients = TRUE,
suppress.warnings = TRUE
suppress.warnings = TRUE,
suppress.special.argument.checks=suppress.special.argument.checks
)

# select ID.colnames
Expand Down Expand Up @@ -724,17 +731,17 @@ CMA_polypharmacy <- function(data = data,
# } else if(.check.medication.groups(medication.groups,
# list.of.medication.classes = unique(data[[medication.class.colname]])))
# {
#
#
# if(is.null(medication.groups)){
# medication.groups <- unique(data[[medication.class.colname]])
# }
#
#
# med.groups.dt <- as.data.table(.fill.medication.groups(medication.groups,
# list.of.medication.classes = unique(data[[medication.class.colname]]),
# already.checked = TRUE))
#
#
# setnames(med.groups.dt, old = "class", new = medication.class.colname)
#
#
# data.copy <- merge(data.copy, med.groups.dt, by = medication.class.colname)

} else {
Expand Down Expand Up @@ -771,7 +778,8 @@ CMA_polypharmacy <- function(data = data,
observation.window.duration=observation.window.duration,
observation.window.duration.unit=observation.window.duration.unit,
date.format=date.format,
suppress.warnings=suppress.warnings);
suppress.warnings=suppress.warnings,
suppress.special.argument.checks=suppress.special.argument.checks);
if( is.null(tmp) || is.null(tmp$CMA) || is.null(tmp$event.info) || is.null(tmp$CMA.intermediate)) return (NULL);

# Construct the return object:
Expand Down
3 changes: 3 additions & 0 deletions AdhereR/inst/wrappers/julia/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Julia wrapper

This folder contains the `Julia` module `adherer.jl` that implementes the `Julia` wrapper for `AdhereR`.
138 changes: 138 additions & 0 deletions AdhereR/inst/wrappers/julia/adherer.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
"""
This Julia module interfaces with the R package AdhereR.
Copyright (C) 2022 Dan Dediu (ddediu@gmail.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

"""
This module allows the transparent use of the `R` package `AdhereR` from `Julia`.
It exports a set of classes, datasets and methods that mirror in the best way
possible those from `R`.
Internally, it uses `RCall` (https://juliainterop.github.io/RCall.jl/stable/) to
"talk" to `R`.
"""
module AdhereR

# The AdhereR R package minimum required versions:
rpkgnameminver = Dict("AdhereR"=>"0.8.1", "AdhereRViz"=>"0.2.1") # minimum required versions

# Error messages:
errmsgs = Dict("UnknownError"=>"Error using RCall to talk to R or AdhereR: please check the details below.",
"AllGood"=>"AdhereR: all seems good to go!",
"RError"=>"The RCall package is required: please make sure RCall and R are correctly installed, and that RCall can 'see' R "*
"(if there are multiple versions of R, please make sure RCall 'sees' the correct one). "*
"In particular, make sure that on Apple Sillicon machines Julia and R are compiled for the same architecture. "*
"Please see the manual for more info.",
"AdhereRNotInstalled"=>"The AdhereR package seems to not be installed in R: "*
"please make sure it is corretly installed in the R version that RCall uses. "*
"Please see the manual for more info.",
"AdhereRVersion"=>"The AdhereR package seems to be installed in R, "*
"but it needs to be at least version '"*rpkgnameminver["AdhereR"]*"'.",
"AdhereRVizNotInstalled"=>"The AdhereRViz package seems to not be installed in R: "*
"while not a show stopper, it means that you cannot do interactive (Shiny) plots. "*
"If do want to do so, please make sure it is corretly installed in the R version that RCall uses. "*
"Please see the manual for more info.",
"AdhereRVizVersion"=>"The AdhereRViz package seems to be installed in R, "*
"but it needs to be at least version '"*rpkgnameminver["AdhereRViz"]*"'."*
"While not a show stopper, it means that you cannot do interactive (Shiny) plots. "*
"If do want to do so, please make sure it is corretly installed in the R version that RCall uses. ")


# Try to load RCall:
try
using RCall
catch
error(errmsgs["RError"])
end

"""
Various initialization stuff, in particular checking if RCall,
R and the R package AdhereR work as intended, and, if not,
guide the user on how to install it effectively.
"""
function __init__()
# Check if RCall works as intended:
x = missing

# 1. Basic checs that RCall talks to R:
try
x = reval("1.0")
if rcopy(x) != 1
error(errmsgs["RError"])
end
catch
error(errmsgs["RError"])
end

# 2. Try to load a base library and do some fancier stuff:
try
R"library(stats)"
R"library(datasets)"
x = R"lm(Sepal.Length ~ Petal.Length, data=iris)"
xa = rcopy(R"$x$coefficients['(Intercept)']")
xb = rcopy(R"$x$coefficients['Petal.Length']")
if round(xa,digits=2) != 4.31 || round(xb,digits=2) != 0.41
error(errmsgs["RError"])
end
catch
error(errmsgs["RError"])
end

# 3. Check AdhereR:
try
R"library(AdhereR)"
catch
error(errmsgs["AdhereRNotInstalled"])
end
try
rscript = "if(!require(AdhereR)) {return(-1)} else {if( compareVersion('" * rpkgnameminver["AdhereR"] * "', as.character(packageVersion('AdhereR'))) > 0 ) {return (-2)} else {return (0)}}"
x = rcopy(reval(rscript))
if x == (-1)
error(errmsgs["AdhereRNotInstalled"])
elseif x == (-2)
error(errmsgs["AdhereRVersion"])
elseif x != 0
error(errmsgs["UnknownError"])
end
catch
end

# 3. Check AdhereRViz:
try
R"library(AdhereRViz)"
catch
warn(errmsgs["AdhereVizRNotInstalled"])
end
try
rscript = "if(!require(AdhereRViz)) {return(-1)} else {if( compareVersion('" * rpkgnameminver["AdhereRViz"] * "', as.character(packageVersion('AdhereRViz'))) > 0 ) {return (-2)} else {return (0)}}"
x = rcopy(reval(rscript))
if x == (-1)
error(errmsgs["AdhereRVizNotInstalled"])
elseif x == (-2)
error(errmsgs["AdhereRVizVersion"])
elseif x != 0
error(errmsgs["UnknownError"])
end
catch
end

# All looks good: let the user know:
println(errmsgs["AllGood"])
end

# The CMA hierarchy:

end

Loading

0 comments on commit 61b5be5

Please sign in to comment.