Skip to content

Commit

Permalink
fixed error messages,update to decision rules
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcarayon committed Aug 24, 2021
1 parent b40b9a1 commit 95af60f
Show file tree
Hide file tree
Showing 30 changed files with 74 additions and 38 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: IDEATools
Title: A Collection of Tools Dedicated to the IDEA4 Method
Version: 2.0.6
Version: 2.0.7
Authors@R:
person(given = "David",
family = "Carayon",
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# IDEATools 2.0.7

* Changed the error message occuring when `read_idea()` fails in `diag_idea()`
* added a better and easier to maintain check for NA's in the output of `read_idea()`
* New categorisation rules for indicators
* New computation rules for items

# IDEATools 2.0.6

* Bug fixes and modifying `plot_idea()` as the unofficial hack `<ggplot_object> + ggsave()` does not work anymore.
Expand Down
23 changes: 21 additions & 2 deletions R/compute_idea.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ compute_idea <- function(data) {

## Extracting metadata from input data
metadata <- data$metadata
version <- metadata$MTD_00
version_number <- as.numeric(stringr::str_remove_all(version, "\\."))


# 5 Decision rules for indicators using custom functions --------------------------------------------------------

Expand All @@ -60,7 +63,15 @@ compute_idea <- function(data) {
}

if (indicateur == "A5") {
value <- ifelse(metadata$MTD_15 >= 0.75, yes = 5, no = sum(items))

if(version_number < 430) {
value <- ifelse(metadata$MTD_15 >= 0.75, yes = 5, no = sum(items))
} else {
value <- sum(items)
}



}

if (indicateur == "A7") {
Expand All @@ -72,7 +83,15 @@ compute_idea <- function(data) {
}

if (indicateur == "A8") {
value <- ifelse(metadata$MTD_15 >= 0.95, yes = 8, no = sum(items))

if(version_number <= 430) {
value <- ifelse(metadata$MTD_15 >= 0.95, yes = 8, no = sum(items))
} else {
value <- sum(items)
}



}

if (indicateur == "A14") {
Expand Down
6 changes: 3 additions & 3 deletions R/diag_idea.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ diag_idea <- function(input, output_directory, type = "single", export_type = c(
## If the first pipeline fails, try the old_idea one
if (any(class(test_version) == "try-error")) {
if (!quiet) {
cli::cat_bullet("Note : Le calculateur ins\u00e9r\u00e9 est soit ancien (Version < 4.2.0) soit incomplet. Tentative de r\u00e9cup\u00e9ration des donn\u00e9es...\n", bullet = "warning", bullet_col = "orange", col = "orange")
cli::cat_bullet("Note : Erreur dans la lecture du calculateur (Utilisez la fonction `read_idea()` pour plus d'informations). Tentative de r\u00e9cup\u00e9ration des donn\u00e9es via un algorithme de secours.\n ", bullet = "warning", bullet_col = "orange", col = "orange")
}

## Reading items (and estimating duration)
Expand Down Expand Up @@ -229,7 +229,7 @@ diag_idea <- function(input, output_directory, type = "single", export_type = c(
## If the first pipeline fails, try the old_idea one
if (any(class(test_version) == "try-error")) {
if (!quiet) {
cli::cat_bullet(paste0("Note : Le calculateur '", basename(i), "' est soit ancien (Version < 4.2.0) soit incomplet. Tentative de r\u00e9cup\u00e9ration des donn\u00e9es...\n"), bullet = "warning", bullet_col = "orange", col = "orange")
cli::cat_bullet("Note : Erreur dans la lecture du calculateur (Utilisez la fonction `read_idea()` pour plus d'informations). Tentative de r\u00e9cup\u00e9ration des donn\u00e9es via un algorithme de secours.\n ", bullet = "warning", bullet_col = "orange", col = "orange")
}

# Old alternative
Expand Down Expand Up @@ -336,7 +336,7 @@ diag_idea <- function(input, output_directory, type = "single", export_type = c(
## If the first pipeline fails, try the old_idea one
if (any(class(test_version) == "try-error")) {
if (!quiet) {
cli::cat_bullet(paste0("Note : Le calculateur '", basename(i), "' est soit ancien (Version < 4.2.0) soit incomplet. Tentative de r\u00e9cup\u00e9ration des donn\u00e9es...\n"), bullet = "warning", bullet_col = "orange", col = "orange")
cli::cat_bullet("Note : Erreur dans la lecture du calculateur (Utilisez la fonction `read_idea()` pour plus d'informations). Tentative de r\u00e9cup\u00e9ration des donn\u00e9es via un algorithme de secours.\n ", bullet = "warning", bullet_col = "orange", col = "orange")
}

# Old alternative
Expand Down
18 changes: 8 additions & 10 deletions R/read_idea.R
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,12 @@ read_idea <- function(input) {
tidyr::drop_na(item)

## Error if not complete

if(version_number < 430) {
if (nrow(tidyr::drop_na(items)) != 118) (stop(paste0("The items field in '", basename(input), "' has ", nrow(items), " entries but expects 118.")))
} else {
if (nrow(tidyr::drop_na(items)) != 119) (stop(paste0("The items field in '", basename(input), "' has ", nrow(items), " entries but expects 119.")))
if (sum(is.na(items$value)) > 0) {
stop(
paste0("The items field in '", basename(input), "' has missing values")
)
}


}

if (filetype %in% c("xls", "xlsx")) {
Expand All @@ -235,10 +233,10 @@ read_idea <- function(input) {
tidyr::drop_na(item)

## Error if not complete
if(version_number < 430) {
if (nrow(tidyr::drop_na(items)) != 118) (stop(paste0("The 118-rows dataframe for items in 'Renvoi BDD' can't be found in range A25:E143 for the file '", basename(input), "'.")))
} else {
if (nrow(tidyr::drop_na(items)) != 119) (stop(paste0("The 119-rows dataframe for items in 'Renvoi BDD' can't be found in range A25:E144 for the file '", basename(input), "'.")))
if (sum(is.na(items$value)) > 0) {
stop(
paste0("The items field in '", basename(input), "' has missing values")
)
}


Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion R/themes.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ theme_idea <- function(base_size = 15, base_family = "") {

# Strip (Used with multiple panels)
strip.background = ggplot2::element_rect(fill = "#2c3e50", color = "black"),
strip.text = ggplot2::element_text(color = white, face = "bold", size = ggplot2::rel(0.8), margin = ggplot2::margin(t = 5, b = 5)),
strip.text = ggplot2::element_text(color = white, face = "bold", size = ggplot2::rel(0.7), margin = ggplot2::margin(t = 5, b = 5)),

# Plot
plot.title = ggplot2::element_text(
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/LICENSE.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/colored_trees.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/decision_rules.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/ideatools_advanced_fr.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/authors.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion docs/news/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ articles:
colored_trees: colored_trees.html
decision_rules: decision_rules.html
ideatools_advanced_fr: ideatools_advanced_fr.html
last_built: 2021-07-22T07:36Z
last_built: 2021-08-24T07:21Z

2 changes: 1 addition & 1 deletion docs/reference/compute_idea.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/diag_idea.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/old_idea.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/pipe.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/plot_idea.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/read_idea.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/show_canvas.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/show_decision_rules.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/theme_idea.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/write_idea.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 95af60f

Please sign in to comment.