Difference between revisions of "OpasnetUtils/Drafts"

From Testiwiki
Jump to: navigation, search
(Calculations)
(Calculations: semi-working showind saved)
Line 24: Line 24:
  
 
'''Functions for ovariable diagnostics
 
'''Functions for ovariable diagnostics
 +
showind has problems with get() but this version of code was acceptable [http://en.opasnet.org/en-opwiki/index.php?title=Special:RTools&id=QcfKMkCd2ewUtZqP].
  
<rcode name="diagnostics" embed=1>
+
<rcode name="diagnostics" embed=0>
 
#This is code Op_en6007/diagnostics on page [OpasnetUtils/Drafts]]
 
#This is code Op_en6007/diagnostics on page [OpasnetUtils/Drafts]]
  
 
library(OpasnetUtils)
 
library(OpasnetUtils)
 +
 +
# Shows a table about ovariables and their index and location changes compared with parents.
 +
# showind has problems with get().
 +
showind <- function(name = ".GlobalEnv", sources = FALSE, prevresults = FALSE) {
 +
  # i ovariable
 +
  # k parent ovariable
 +
  # l index in (parent) ovariable
 +
  deptable <- data.frame()
 +
  for(i in ls(name = name)) {
 +
    #    d <- g#et(i)
 +
    if(class(get(i)) == "ovariable") {
 +
      depind <- list()
 +
      if(nrow(get(i)@dependencies)>0) {
 +
        dep <- paste(get(i)@dependencies$Name, collapse = ", ")
 +
        for(k in get(i)@dependencies$Name){
 +
          if(!exists(k)) cat(k, "does not exist.\n") else {
 +
            if(class(get(k)) != "ovariable") cat(k, "is not an ovariable.\n") else {
 +
              #              ko <- g#et(k)
 +
              # We don't want to look at all Iters, but forbidden <-get() makes this tricky., so we just disable
 +
              # this functionality at the moment. koIter should be replaced by ko$Iter where ko <- g#et(k)
 +
              if("Iter" %in% colnames(get(k)@output)) koIter <- as.factor(max(as.numeric(as.character(get(k)$Iter))))
 +
              cols <- colnames(get(k)@output)
 +
              if(!sources) cols <- cols[!grepl("Source$", cols)]
 +
              if(!prevresults) cols <- cols[!grepl("Result$", cols)]
 +
              for(l in cols) {
 +
                if(l %in% names(depind)) {
 +
                  depind[[l]] <- union(depind[[l]], unique(get(k)@output[[l]]))
 +
                } else {
 +
                  newind <- list(unique(get(k)@output[[l]]))
 +
                  names(newind) <- l
 +
                  depind <- c(depind, newind)
 +
                }
 +
              }
 +
            }
 +
          }
 +
        }
 +
      } else {
 +
        dep <- "No dependencies"
 +
      }
 +
      curcols <- colnames(get(i)@output)
 +
      if(!sources) curcols <- curcols[!grepl("Source$", curcols)]
 +
      if(!prevresults) curcols <- curcols[!grepl("Result$", curcols)]
 +
      droploc <- character()
 +
      for(m in curcols) {
 +
        if(!is.numeric(get(i)@output[[m]])) {
 +
          drops <- setdiff(depind[[m]], unique(get(i)@output[[m]]))
 +
          if(length(drops>0)) {
 +
            droploc <- paste(
 +
              droploc,
 +
              paste(
 +
                m,
 +
                paste(drops, collapse = ", "),
 +
                sep = ": "
 +
              ),
 +
              sep = " | "
 +
            )
 +
          }
 +
        }
 +
      }
 +
      if(length(droploc)==0) droploc <- NA
 +
      deptable <- rbind(
 +
        deptable,
 +
        data.frame(
 +
          Ovariable = i,
 +
          Size = nrow(d@output),
 +
          Dependencies = dep,
 +
          Current = paste(curcols, collapse = ", "),
 +
          Dropped = paste(setdiff(names(depind), curcols), collapse = ", "),
 +
          New = paste(setdiff(curcols, names(depind)), collapse = ", "),
 +
          Dropped_locations = droploc
 +
        )
 +
      )
 +
    }
 +
  }
 +
  return(deptable)
 +
}
  
 
ovashapetest <- function(ova) {
 
ovashapetest <- function(ova) {
Line 115: Line 192:
 
}
 
}
  
objects.store(binoptest, showLoctable, ovashapetest)
+
objects.store(showind, binoptest, showLoctable, ovashapetest)
cat("Functions binoptest, showLoctable, ovashapetest stored.\n")
+
cat("Functions showind, binoptest, showLoctable, ovashapetest stored.\n")
 
</rcode>
 
</rcode>
  

Revision as of 08:14, 6 June 2017



Question

Which functions are so useful that they should be taken into OpasnetUtils package? This page contains draft function which will be included when they are good enough and found important.

Answer

Call the objects stored by this code from another rode with this command:

objects.latest("Op_en6007", code_name = "answer") # Old version that fetches all objects, depreciated and not updated.
objects.latest("Op_en6007", code_name = "diagnostics") # Functions for ovariable and model diagnostics: ovashapetest, showLoctable, binoptest
objects.latest("Op_en6007", code_name = "webropol") # Functions for operating with Webropol data
objects.latest("Op_en6007", code_name = "miscellaneous") # Functions for various tasks
objects.latest("Op_en6007", code_name = "gis") # Functions for ovariable, KML and Googl maps interactions

Rationale

Calculations

Functions for ovariable diagnostics showind has problems with get() but this version of code was acceptable [1].

+ Show code

Functions for Webropol data

+ Show code

Miscellaneous functions

+ Show code

Functions for GIS data

+ Show code

See also

References


Related files

<mfanonymousfilelist></mfanonymousfilelist>