From 71f6370f52e24c43bd1ec00c52f5cf4654a2f12d Mon Sep 17 00:00:00 2001 From: Preston Burns Date: Mon, 22 Apr 2019 13:56:51 -0400 Subject: [PATCH 01/11] update safetyHistogram to v2.2.3 --- .../safetyHistogram.js | 10 ++++++++++ inst/htmlwidgets/safetyHistogram.yaml | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) rename inst/htmlwidgets/lib/{safety-histogram-2.2.2 => safety-histogram-2.2.3}/safetyHistogram.js (98%) diff --git a/inst/htmlwidgets/lib/safety-histogram-2.2.2/safetyHistogram.js b/inst/htmlwidgets/lib/safety-histogram-2.2.3/safetyHistogram.js similarity index 98% rename from inst/htmlwidgets/lib/safety-histogram-2.2.2/safetyHistogram.js rename to inst/htmlwidgets/lib/safety-histogram-2.2.3/safetyHistogram.js index d1b2727d..5fff2830 100644 --- a/inst/htmlwidgets/lib/safety-histogram-2.2.2/safetyHistogram.js +++ b/inst/htmlwidgets/lib/safety-histogram-2.2.3/safetyHistogram.js @@ -196,6 +196,11 @@ //Define default details. var defaultDetails = [{ value_col: settings.id_col, label: 'Subject Identifier' }]; + + if (!(settings.filters instanceof Array)) { + settings.filters = typeof settings.filters == 'string' ? [settings.filters] : []; + } + if (settings.filters) settings.filters.forEach(function(filter) { return defaultDetails.push({ @@ -219,6 +224,11 @@ label: 'Upper Limit of Normal' }); + //If [settings.details] is not an array: + if (!(settings.details instanceof Array)) { + settings.details = typeof settings.details == 'string' ? [settings.details] : []; + } + //If [settings.details] is not specified: if (!settings.details) settings.details = defaultDetails; else { diff --git a/inst/htmlwidgets/safetyHistogram.yaml b/inst/htmlwidgets/safetyHistogram.yaml index 2f678ba6..4277978b 100644 --- a/inst/htmlwidgets/safetyHistogram.yaml +++ b/inst/htmlwidgets/safetyHistogram.yaml @@ -9,7 +9,7 @@ dependencies: script: webcharts.js stylesheet: webcharts.css - name: safety-histogram - version: 2.2.2 - src: htmlwidgets/lib/safety-histogram-2.2.2 + version: 2.2.3 + src: htmlwidgets/lib/safety-histogram-2.2.3 script: safetyHistogram.js From 9dd254deb37d019280b5235bd64cc4ef2506ba7d Mon Sep 17 00:00:00 2001 From: Preston Burns Date: Mon, 22 Apr 2019 14:14:55 -0400 Subject: [PATCH 02/11] update eDish to v0.16.5 --- inst/htmlwidgets/eDISH.yaml | 4 ++-- .../safetyedish.js | 24 +++++++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) rename inst/htmlwidgets/lib/{safety-eDISH-0.16.3 => safety-eDISH-0.16.5}/safetyedish.js (99%) diff --git a/inst/htmlwidgets/eDISH.yaml b/inst/htmlwidgets/eDISH.yaml index 17ad864a..3faf2d99 100644 --- a/inst/htmlwidgets/eDISH.yaml +++ b/inst/htmlwidgets/eDISH.yaml @@ -9,6 +9,6 @@ dependencies: script: webcharts.js stylesheet: webcharts.css - name: safety-eDish - version: 0.16.3 - src: htmlwidgets/lib/safety-eDISH-0.16.3 + version: 0.16.5 + src: htmlwidgets/lib/safety-eDISH-0.16.5 script: safetyedish.js diff --git a/inst/htmlwidgets/lib/safety-eDISH-0.16.3/safetyedish.js b/inst/htmlwidgets/lib/safety-eDISH-0.16.5/safetyedish.js similarity index 99% rename from inst/htmlwidgets/lib/safety-eDISH-0.16.3/safetyedish.js rename to inst/htmlwidgets/lib/safety-eDISH-0.16.5/safetyedish.js index 03550241..b70faecf 100644 --- a/inst/htmlwidgets/lib/safety-eDISH-0.16.3/safetyedish.js +++ b/inst/htmlwidgets/lib/safety-eDISH-0.16.5/safetyedish.js @@ -395,7 +395,7 @@ //make sure filters is an Array if (!(settings.filters instanceof Array)) { - settings.filters = []; + settings.filters = typeof settings.filters == 'string' ? [settings.filters] : []; } //Define default details. @@ -473,15 +473,29 @@ // If settings.analysisFlag is null if (!settings.analysisFlag) settings.analysisFlag = { value_col: null, values: [] }; - + if (!settings.analysisFlag.value_col) settings.analysisFlag.value_col = null; + if (!(settings.analysisFlag.values instanceof Array)) { + settings.analysisFlag.values = + typeof settings.analysisFlag.values == 'string' + ? [settings.analysisFlag.values] + : []; + } //if it is null, set settings.baseline.value_col to settings.studyday_col. if (!settings.baseline) settings.baseline = { value_col: null, values: [] }; - if (settings.baseline.values.length == 0) settings.baseline.values = [0]; if (!settings.baseline.value_col) settings.baseline.value_col = settings.studyday_col; + if (!(settings.baseline.values instanceof Array)) { + settings.baseline.values = + typeof settings.baseline.values == 'string' ? [settings.baseline.values] : []; + } //parse x_ and y_options to array if needed - if (typeof settings.x_options == 'string') settings.x_options = [settings.x_options]; - if (typeof settings.y_options == 'string') settings.y_options = [settings.y_options]; + if (!(settings.x_options instanceof Array)) { + settings.x_options = typeof settings.x_options == 'string' ? [settings.x_options] : []; + } + + if (!(settings.x_options instanceof Array)) { + settings.y_options = typeof settings.y_options == 'string' ? [settings.y_options] : []; + } // track initial Cutpoint (lets us detect when cutpoint should change) settings.cuts.x = settings.x.column; From d0b6098403cf8a5eb61d3e6f31a36f428b1b2ae2 Mon Sep 17 00:00:00 2001 From: Preston Burns Date: Mon, 22 Apr 2019 15:54:49 -0400 Subject: [PATCH 03/11] handle vectors in trimData --- R/trimData.R | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/R/trimData.R b/R/trimData.R index b7e72c54..a3b99af3 100644 --- a/R/trimData.R +++ b/R/trimData.R @@ -28,23 +28,39 @@ trimData <- function(data, settings, chart="edish"){ # Add items in vectors to list individually dataVectorKeys <- allKeys %>% filter(.data$setting_type =="vector") %>% pull(.data$text_key) %>% textKeysToList() + + vectorVars <- list() + for(key in dataVectorKeys){ current<-getSettingValue(key, settings=settings) + if (length(current) > 0 ) { - for (i in 1:length(current)){ - newKey <- key - newKey[[1+length(newKey)]]<-i - sub <- current[[i]] - if(typeof(sub)=="list"){ - newKey[[1+length(newKey)]]<-"value_col" + # handle vectors separately + if (typeof(current) == "character") { + for (i in 1:length(current)){ + vectorVars <- append(vectorVars,current[i]) + } + } else { + for (i in 1:length(current)){ + newKey <- key + newKey[[1+length(newKey)]]<-i + sub <- current[[i]] + if(typeof(sub)=="list"){ + newKey[[1+length(newKey)]]<-"value_col" + } + dataKeys[[1+length(dataKeys)]]<-newKey } - dataKeys[[1+length(dataKeys)]]<-newKey } } } - settings_values <- map(dataKeys, function(x) {return(getSettingValue(x, settings))}) + + settings_values <- map(dataKeys, function(x) {return(getSettingValue(x, settings))}) + + #add variables from vectors to the list before intersect + settings_values <- c(settings_values, vectorVars) + common_cols <- intersect(col_names,settings_values) data_subset <- select(data, unlist(common_cols)) From 3a9ed5d0cf0701ea4cbe3dee91286537c0780508 Mon Sep 17 00:00:00 2001 From: Preston Burns Date: Tue, 23 Apr 2019 10:28:09 -0400 Subject: [PATCH 04/11] fix getSettingValue instead --- R/getSettingValue.R | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/R/getSettingValue.R b/R/getSettingValue.R index 9794482c..6d213d5e 100644 --- a/R/getSettingValue.R +++ b/R/getSettingValue.R @@ -23,16 +23,21 @@ getSettingValue <- function(key,settings){ # Get the value for the first key firstKey <- key[[1]] value <- settings[[firstKey]] - - if(length(key)>1 ){ #If there are more keys and the value is a list, iterate if(typeof(value)=="list"){ value<-getSettingValue(key[2:length(key)],value) + #If position is provided and the value is a character vector + }else if(typeof(value) == "character"){ + value<-value[[key[[2]]]] }else{ #If there are more keys, but the value is not a list, return NULL value<-NULL } + } else if (length(value) >1) { + } + + return(value) } \ No newline at end of file From 3f46a62f5d57004cdde5359601f99665bd7ba337 Mon Sep 17 00:00:00 2001 From: Preston Burns Date: Tue, 23 Apr 2019 10:29:50 -0400 Subject: [PATCH 05/11] and get rid of old fix --- R/getSettingValue.R | 5 ++--- R/trimData.R | 36 ++++++++++-------------------------- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/R/getSettingValue.R b/R/getSettingValue.R index 6d213d5e..f13d3c68 100644 --- a/R/getSettingValue.R +++ b/R/getSettingValue.R @@ -23,6 +23,8 @@ getSettingValue <- function(key,settings){ # Get the value for the first key firstKey <- key[[1]] value <- settings[[firstKey]] + + if(length(key)>1 ){ #If there are more keys and the value is a list, iterate if(typeof(value)=="list"){ @@ -35,9 +37,6 @@ getSettingValue <- function(key,settings){ value<-NULL } } else if (length(value) >1) { - } - - return(value) } \ No newline at end of file diff --git a/R/trimData.R b/R/trimData.R index a3b99af3..70e05af6 100644 --- a/R/trimData.R +++ b/R/trimData.R @@ -19,48 +19,32 @@ trimData <- function(data, settings, chart="edish"){ - + ## Remove columns not in settings ## col_names <- colnames(data) - + allKeys <- getSettingsMetadata(charts=chart, filter_expr = .data$column_mapping, cols = c("text_key","setting_type")) dataKeys <- allKeys %>% filter(.data$setting_type !="vector") %>% pull(.data$text_key) %>% textKeysToList() - + # Add items in vectors to list individually dataVectorKeys <- allKeys %>% filter(.data$setting_type =="vector") %>% pull(.data$text_key) %>% textKeysToList() - - vectorVars <- list() - for(key in dataVectorKeys){ current<-getSettingValue(key, settings=settings) - if (length(current) > 0 ) { - # handle vectors separately - if (typeof(current) == "character") { - for (i in 1:length(current)){ - vectorVars <- append(vectorVars,current[i]) - } - } else { - for (i in 1:length(current)){ - newKey <- key - newKey[[1+length(newKey)]]<-i - sub <- current[[i]] - if(typeof(sub)=="list"){ - newKey[[1+length(newKey)]]<-"value_col" - } - dataKeys[[1+length(dataKeys)]]<-newKey + for (i in 1:length(current)){ + newKey <- key + newKey[[1+length(newKey)]]<-i + sub <- current[[i]] + if(typeof(sub)=="list"){ + newKey[[1+length(newKey)]]<-"value_col" } + dataKeys[[1+length(dataKeys)]]<-newKey } } } - - settings_values <- map(dataKeys, function(x) {return(getSettingValue(x, settings))}) - #add variables from vectors to the list before intersect - settings_values <- c(settings_values, vectorVars) - common_cols <- intersect(col_names,settings_values) data_subset <- select(data, unlist(common_cols)) From 3e5386ae0841d8503aa8d5aac5b501e03df1c8d2 Mon Sep 17 00:00:00 2001 From: Preston Burns Date: Tue, 23 Apr 2019 11:01:23 -0400 Subject: [PATCH 06/11] remove stray else if --- R/getSettingValue.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/getSettingValue.R b/R/getSettingValue.R index f13d3c68..3f084fbb 100644 --- a/R/getSettingValue.R +++ b/R/getSettingValue.R @@ -36,7 +36,6 @@ getSettingValue <- function(key,settings){ #If there are more keys, but the value is not a list, return NULL value<-NULL } - } else if (length(value) >1) { } return(value) } \ No newline at end of file From d264bed167fd7dec986f44e7d109f9efe1745485 Mon Sep 17 00:00:00 2001 From: Preston Burns Date: Tue, 23 Apr 2019 13:52:50 -0400 Subject: [PATCH 07/11] update eDish js --- inst/htmlwidgets/eDISH.yaml | 4 ++-- .../safetyedish.js | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) rename inst/htmlwidgets/lib/{safety-eDISH-0.16.5 => safety-eDISH-0.16.7}/safetyedish.js (99%) diff --git a/inst/htmlwidgets/eDISH.yaml b/inst/htmlwidgets/eDISH.yaml index 3faf2d99..48ec8a0e 100644 --- a/inst/htmlwidgets/eDISH.yaml +++ b/inst/htmlwidgets/eDISH.yaml @@ -9,6 +9,6 @@ dependencies: script: webcharts.js stylesheet: webcharts.css - name: safety-eDish - version: 0.16.5 - src: htmlwidgets/lib/safety-eDISH-0.16.5 + version: 0.16.7 + src: htmlwidgets/lib/safety-eDISH-0.16.7 script: safetyedish.js diff --git a/inst/htmlwidgets/lib/safety-eDISH-0.16.5/safetyedish.js b/inst/htmlwidgets/lib/safety-eDISH-0.16.7/safetyedish.js similarity index 99% rename from inst/htmlwidgets/lib/safety-eDISH-0.16.5/safetyedish.js rename to inst/htmlwidgets/lib/safety-eDISH-0.16.7/safetyedish.js index b70faecf..98f329ab 100644 --- a/inst/htmlwidgets/lib/safety-eDISH-0.16.5/safetyedish.js +++ b/inst/htmlwidgets/lib/safety-eDISH-0.16.7/safetyedish.js @@ -445,6 +445,11 @@ }); } + //parse details to array if needed + if (!(settings.details instanceof Array)) { + settings.details = typeof settings.details == 'string' ? [settings.details] : []; + } + //If [settings.details] is not specified: if (!settings.details) settings.details = defaultDetails; else { @@ -493,7 +498,7 @@ settings.x_options = typeof settings.x_options == 'string' ? [settings.x_options] : []; } - if (!(settings.x_options instanceof Array)) { + if (!(settings.y_options instanceof Array)) { settings.y_options = typeof settings.y_options == 'string' ? [settings.y_options] : []; } From 3fe82223ec8229f8cdaf6b614d195e37147d6d75 Mon Sep 17 00:00:00 2001 From: Preston Burns Date: Tue, 23 Apr 2019 14:01:49 -0400 Subject: [PATCH 08/11] update webcharts js --- inst/htmlwidgets/eDISH.yaml | 4 +- .../webcharts.css | 0 .../webcharts.js | 69 +++++++++++++------ inst/htmlwidgets/safetyHistogram.yaml | 4 +- 4 files changed, 53 insertions(+), 24 deletions(-) rename inst/htmlwidgets/lib/{webcharts-1.11.3 => webcharts-1.11.5}/webcharts.css (100%) rename inst/htmlwidgets/lib/{webcharts-1.11.3 => webcharts-1.11.5}/webcharts.js (98%) diff --git a/inst/htmlwidgets/eDISH.yaml b/inst/htmlwidgets/eDISH.yaml index 48ec8a0e..443bcbff 100644 --- a/inst/htmlwidgets/eDISH.yaml +++ b/inst/htmlwidgets/eDISH.yaml @@ -4,8 +4,8 @@ dependencies: src: htmlwidgets/lib/d3-3.5.17 script: d3.v3.min.js - name: webcharts - version: 1.11.3 - src: htmlwidgets/lib/webcharts-1.11.3 + version: 1.11.5 + src: htmlwidgets/lib/webcharts-1.11.5 script: webcharts.js stylesheet: webcharts.css - name: safety-eDish diff --git a/inst/htmlwidgets/lib/webcharts-1.11.3/webcharts.css b/inst/htmlwidgets/lib/webcharts-1.11.5/webcharts.css similarity index 100% rename from inst/htmlwidgets/lib/webcharts-1.11.3/webcharts.css rename to inst/htmlwidgets/lib/webcharts-1.11.5/webcharts.css diff --git a/inst/htmlwidgets/lib/webcharts-1.11.3/webcharts.js b/inst/htmlwidgets/lib/webcharts-1.11.5/webcharts.js similarity index 98% rename from inst/htmlwidgets/lib/webcharts-1.11.3/webcharts.js rename to inst/htmlwidgets/lib/webcharts-1.11.5/webcharts.js index e6fe9061..24ad10ef 100644 --- a/inst/htmlwidgets/lib/webcharts-1.11.3/webcharts.js +++ b/inst/htmlwidgets/lib/webcharts-1.11.5/webcharts.js @@ -6,7 +6,7 @@ : (global.webCharts = factory(global.d3)); })(typeof self !== 'undefined' ? self : this, function(d3) { 'use strict'; - var version = '1.11.3'; + var version = '1.11.5'; function init(data) { var _this = this; @@ -518,7 +518,7 @@ if (this.filters.length) { this.filters.forEach(function(filter) { _this.filtered_data = _this.filtered_data.filter(function(d) { - return filter.val === 'All' + return filter.all === true && filter.index === 0 ? d : filter.val instanceof Array ? filter.val.indexOf(d[filter.col]) > -1 @@ -1092,7 +1092,7 @@ if (this.filters.length) { this.filters.forEach(function(e) { filtered = filtered.filter(function(d) { - return e.val === 'All' + return e.all === true && e.index === 0 ? d : e.val instanceof Array ? e.val.indexOf(d[e.col]) > -1 @@ -1831,6 +1831,7 @@ function drawBars(marks) { var _this = this; + var chart = this; var rawData = this.raw_data; var config = this.config; @@ -1896,7 +1897,7 @@ .attr('class', function(d) { return 'wc-data-mark bar ' + d.key; }) - .style('clip-path', 'url(#' + this.id + ')') + .style('clip-path', 'url(#' + chart.id + ')') .attr('y', this.y(0)) .attr('height', 0) .append('title'); @@ -2029,7 +2030,7 @@ .attr('class', function(d) { return 'wc-data-mark bar ' + d.key; }) - .style('clip-path', 'url(#' + this.id + ')') + .style('clip-path', 'url(#' + chart.id + ')') .attr('x', this.x(0)) .attr('width', 0) .append('title'); @@ -2157,7 +2158,7 @@ .attr('class', function(d) { return 'wc-data-mark bar ' + d.key; }) - .style('clip-path', 'url(#' + this.id + ')') + .style('clip-path', 'url(#' + chart.id + ')') .attr('y', this.y(0)) .attr('height', 0) .append('title'); @@ -2267,7 +2268,7 @@ .attr('class', function(d) { return 'wc-data-mark bar ' + d.key; }) - .style('clip-path', 'url(#' + this.id + ')') + .style('clip-path', 'url(#' + chart.id + ')') .attr('x', this.x(0)) .attr('width', 0) .append('title'); @@ -2362,6 +2363,7 @@ function drawLines(marks) { var _this = this; + var chart = this; var config = this.config; var line = d3.svg .line() @@ -2409,6 +2411,7 @@ var linePaths = line_grps .select('path') .attr('class', 'wc-data-mark') + .style('clip-path', 'url(#' + chart.id + ')') .datum(function(d) { return d.values; }) @@ -2458,6 +2461,7 @@ function drawPoints(marks) { var _this = this; + var chart = this; var config = this.config; var point_supergroups = this.svg.selectAll('.point-supergroup').data(marks, function(d, i) { @@ -2496,6 +2500,7 @@ //static attributes points .select('circle') + .style('clip-path', 'url(#' + chart.id + ')') .attr( 'fill-opacity', config.fill_opacity || config.fill_opacity === 0 ? config.fill_opacity : 0.6 @@ -2568,6 +2573,7 @@ function drawText(marks) { var _this = this; + var chart = this; var config = this.config; var textSupergroups = this.svg.selectAll('.text-supergroup').data(marks, function(d, i) { @@ -2610,7 +2616,7 @@ texts.each(attachMarks); // parse text like tooltips - texts.select('text').text(function(d) { + texts.select('text').style('clip-path', 'url(#' + chart.id + ')').text(function(d) { var tt = d.mark.text || ''; var xformat = config.x.summary === 'percent' ? d3.format('0%') @@ -3061,13 +3067,16 @@ } function makeSubsetterControl(control, control_wrap) { - var targets = this.targets; + var targets = this.targets; // associated charts and tables. + + //dropdown selection var changer = control_wrap .append('select') - .attr('class', 'changer') + .classed('changer', true) .attr('multiple', control.multiple ? true : null) .datum(control); + //dropdown option data var option_data = control.values ? control.values : d3 @@ -3080,17 +3089,24 @@ return f; }) ) - .values(); - option_data.sort(naturalSorter); + .values() + .sort(naturalSorter); // only sort when values are derived + //initial dropdown option control.start = control.start ? control.start : control.loose ? option_data[0] : null; + //conditionally add All option if (!control.multiple && !control.start) { option_data.unshift('All'); + control.all = true; + } else { + control.all = false; } + //what does loose mean? control.loose = !control.loose && control.start ? true : control.loose; + //dropdown options selection var options = changer .selectAll('option') .data(option_data) @@ -3103,6 +3119,7 @@ return d === control.start; }); + //define filter object for each associated target targets.forEach(function(e) { var match = e.filters .slice() @@ -3113,16 +3130,20 @@ if (match > -1) { e.filters[match] = { col: control.value_col, - val: control.start ? control.start : 'All', + val: control.start ? control.start : !control.multiple ? 'All' : option_data, + index: 0, choices: option_data, - loose: control.loose + loose: control.loose, + all: control.all }; } else { e.filters.push({ col: control.value_col, - val: control.start ? control.start : 'All', + val: control.start ? control.start : !control.multiple ? 'All' : option_data, + index: 0, choices: option_data, - loose: control.loose + loose: control.loose, + all: control.all }); } }); @@ -3139,6 +3160,7 @@ } } + //add event listener to control changer.on('change', function(d) { if (control.multiple) { var values = options @@ -3152,8 +3174,10 @@ var new_filter = { col: control.value_col, val: values, + index: null, // could specify an array of indices but seems like a waste of resources give it doesn't inform anything without an overall 'All' choices: option_data, - loose: control.loose + loose: control.loose, + all: control.all }; targets.forEach(function(e) { setSubsetter(e, new_filter); @@ -3165,11 +3189,14 @@ }); } else { var value = d3.select(this).select('option:checked').property('text'); + var index = d3.select(this).select('option:checked').property('index'); var _new_filter = { col: control.value_col, val: value, + index: index, choices: option_data, - loose: control.loose + loose: control.loose, + all: control.all }; targets.forEach(function(e) { setSubsetter(e, _new_filter); @@ -3273,7 +3300,8 @@ this.filters && this.filters.some(function(filter) { return ( - (typeof filter.val === 'string' && filter.val !== 'All') || + (typeof filter.val === 'string' && + !(filter.all === true && filter.index === 0)) || (Array.isArray(filter.val) && filter.val.length < filter.choices.length) ); }) @@ -3282,7 +3310,8 @@ this.filters .filter(function(filter) { return ( - (typeof filter.val === 'string' && filter.val !== 'All') || + (typeof filter.val === 'string' && + !(filter.all === true && filter.index === 0)) || (Array.isArray(filter.val) && filter.val.length < filter.choices.length) ); }) diff --git a/inst/htmlwidgets/safetyHistogram.yaml b/inst/htmlwidgets/safetyHistogram.yaml index 4277978b..1982a9ac 100644 --- a/inst/htmlwidgets/safetyHistogram.yaml +++ b/inst/htmlwidgets/safetyHistogram.yaml @@ -4,8 +4,8 @@ dependencies: src: htmlwidgets/lib/d3-3.5.17 script: d3.v3.min.js - name: webcharts - version: 1.11.3 - src: htmlwidgets/lib/webcharts-1.11.3 + version: 1.11.5 + src: htmlwidgets/lib/webcharts-1.11.5 script: webcharts.js stylesheet: webcharts.css - name: safety-histogram From 92757737ac6eb64eb0ad36452d9cb873aebb19b9 Mon Sep 17 00:00:00 2001 From: jwildfire Date: Tue, 23 Apr 2019 11:25:32 -0700 Subject: [PATCH 09/11] update getSettingValue and add tests --- R/getSettingValue.R | 6 +++--- tests/testthat/test_getSettingValue.R | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/R/getSettingValue.R b/R/getSettingValue.R index 3f084fbb..fac49b1a 100644 --- a/R/getSettingValue.R +++ b/R/getSettingValue.R @@ -29,9 +29,9 @@ getSettingValue <- function(key,settings){ #If there are more keys and the value is a list, iterate if(typeof(value)=="list"){ value<-getSettingValue(key[2:length(key)],value) - #If position is provided and the value is a character vector - }else if(typeof(value) == "character"){ - value<-value[[key[[2]]]] + #If position is provided and the value is a vector + }else if(typeof(key[[2]])=="double" & length(value)>=key[[2]] & length(key)==2){ + value<-value[[key[[2]]]] }else{ #If there are more keys, but the value is not a list, return NULL value<-NULL diff --git a/tests/testthat/test_getSettingValue.R b/tests/testthat/test_getSettingValue.R index 59f5ac00..cf577d38 100644 --- a/tests/testthat/test_getSettingValue.R +++ b/tests/testthat/test_getSettingValue.R @@ -17,6 +17,23 @@ test_that("different data types for `key` parameter work as expected",{ expect_equal(getSettingValue(key=list("measure_values",1),settings=testSettings),"Aminotransferase, alanine (ALT)") }) +test_that("can get a specific item out of a vector if desired",{ + filter_vector = list(filters=c("SEX","AGE","RACE")) + filter_list = list(filters=list("SEX","AGE","RACE")) + expect_equal(getSettingValue(key=list("filters"),settings=filter_vector),c("SEX","AGE","RACE")) + expect_equal(getSettingValue(key=list("filters",2),settings=filter_vector),"AGE") + expect_null(getSettingValue(key=list("filters",2,"test"),settings=filter_vector)) + expect_null(getSettingValue(key=list("filters",4),settings=filter_vector)) + expect_null(getSettingValue(key=list("filters","4"),settings=filter_vector)) + + + + expect_equal(getSettingValue(key=list("filters"),settings=filter_list),list("SEX","AGE","RACE")) + expect_equal(getSettingValue(key=list("filters",2),settings=filter_list),"AGE") + + +}) + test_that("returns null if the setting isn't found",{ expect_null(getSettingValue(key="testKeyandmore",settings=list(testKey="ABC"))) expect_null(getSettingValue(key=c("a","b","c"),settings=list(testKey="ABC"))) From 7c1b0e4c3048697c1c0cc7b723abb8d0803225b6 Mon Sep 17 00:00:00 2001 From: Preston Burns Date: Tue, 23 Apr 2019 14:44:47 -0400 Subject: [PATCH 10/11] fix array getSettingValue bug --- R/getSettingValue.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/getSettingValue.R b/R/getSettingValue.R index fac49b1a..94681089 100644 --- a/R/getSettingValue.R +++ b/R/getSettingValue.R @@ -30,7 +30,7 @@ getSettingValue <- function(key,settings){ if(typeof(value)=="list"){ value<-getSettingValue(key[2:length(key)],value) #If position is provided and the value is a vector - }else if(typeof(key[[2]])=="double" & length(value)>=key[[2]] & length(key)==2){ + }else if(typeof(key[[2]])=="integer" & length(value)>=key[[2]] & length(key)==2){ value<-value[[key[[2]]]] }else{ #If there are more keys, but the value is not a list, return NULL From 29b83a72a5dc75cfd1e215948e63d6cfdd5553f0 Mon Sep 17 00:00:00 2001 From: Preston Burns Date: Tue, 23 Apr 2019 15:04:09 -0400 Subject: [PATCH 11/11] change getSettingValue if to is.numeric --- R/getSettingValue.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/getSettingValue.R b/R/getSettingValue.R index 94681089..dc8a7078 100644 --- a/R/getSettingValue.R +++ b/R/getSettingValue.R @@ -30,7 +30,7 @@ getSettingValue <- function(key,settings){ if(typeof(value)=="list"){ value<-getSettingValue(key[2:length(key)],value) #If position is provided and the value is a vector - }else if(typeof(key[[2]])=="integer" & length(value)>=key[[2]] & length(key)==2){ + }else if(is.numeric(key[[2]]) & length(value)>=key[[2]] & length(key)==2){ value<-value[[key[[2]]]] }else{ #If there are more keys, but the value is not a list, return NULL