diff histogramdiscrete.r @ 1:344ac3ca7557 draft default tip

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 4494db13b69987fbc97d47177d2a5956e46e927b"
author iuc
date Wed, 17 Nov 2021 09:06:59 +0000
parents a87a3773d8ed
children
line wrap: on
line diff
--- a/histogramdiscrete.r	Fri Mar 09 08:23:08 2018 -0500
+++ b/histogramdiscrete.r	Wed Nov 17 09:06:59 2021 +0000
@@ -1,3 +1,7 @@
+zero <- function(v) {
+    0
+}
+
 # wrapper
 wrapper <- function(table, columns, options) {
 
@@ -9,46 +13,46 @@
     for (key in names(columns)) {
         # load column data
         column <- as.numeric(columns[key])
-        
+
         # ensure string column
         column_data <- as.character(table[column][[1]])
-    
+
         # collect vectors in list
         m <- append(m, list(column_data))
     }
-    
+
     # get alphabetically sorted bins
     bins <- sort(unique(unlist(m)))
-    
+
     # add first column
     l <- append(l, list(bins))
-    
+
     # loop through all columns
     for (key in seq(m)) {
         # reset bins
-        bins = sapply(bins, function(v) { 0 })
-        
+        bins <- sapply(bins, zero)
+
         # load column data
         column_data <- m[[key]]
-        
+
         # create hist data
         table_data <- table(column_data)
-        
+
         # transfer counts to bins
         for (id in names(table_data)) {
             bins[id] <- table_data[id]
         }
-        
+
         # normalize densities
         total <- length(column_data)
         if (total > 0) {
-            bins = bins / total
+            bins <- bins / total
         }
-        
+
         # collect vectors in list
         l <- append(l, list(bins))
     }
 
     # return
-    return (l)
+    return(l)
 }