[Returnanalytics-commits] r3488 - pkg/PortfolioAnalytics/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jul 29 21:25:10 CEST 2014


Author: rossbennett34
Date: 2014-07-29 21:25:09 +0200 (Tue, 29 Jul 2014)
New Revision: 3488

Modified:
   pkg/PortfolioAnalytics/R/generics.R
Log:
slimming down output of print method for portfolio objects

Modified: pkg/PortfolioAnalytics/R/generics.R
===================================================================
--- pkg/PortfolioAnalytics/R/generics.R	2014-07-29 18:22:40 UTC (rev 3487)
+++ pkg/PortfolioAnalytics/R/generics.R	2014-07-29 19:25:09 UTC (rev 3488)
@@ -156,12 +156,12 @@
   cat(rep("*", 50) ,"\n", sep="")
   
   cat("\nCall:\n", paste(deparse(x$call), sep = "\n", collapse = "\n"), 
-      "\n", sep = "")
+      "\n\n", sep = "")
   
   # Assets
-  cat("\nAssets\n")
+  #cat("\nAssets\n")
   nassets <- length(x$assets)
-  cat("Number of assets:", nassets, "\n\n")
+  cat("Number of assets:", nassets, "\n")
   cat("Asset Names\n")
   print(head(names(x$assets), 10))
   if(nassets > 10){
@@ -184,9 +184,9 @@
   }
   
   # Constraints
-  cat("\nConstraints\n")
   nconstraints <- length(x$constraints)
   if(nconstraints > 0){
+    cat("\nConstraints\n")
     # logical vector of enabled constraints
     enabled.constraints <- which(sapply(x$constraints, function(x) x$enabled))
     n.enabled.constraints <- ifelse(length(enabled.constraints) > 0, length(enabled.constraints), 0)
@@ -196,8 +196,8 @@
   }
   # character vector of constraint types
   names.constraints <- sapply(x$constraints, function(x) x$type)
-  cat("Number of constraints:", nconstraints, "\n")
-  cat("Number of enabled constraints:", n.enabled.constraints, "\n")
+  #cat("Number of constraints:", nconstraints, "\n")
+  #cat("Number of enabled constraints:", n.enabled.constraints, "\n")
   if(length(enabled.constraints) > 0){
     cat("Enabled constraint types\n")
     constraints <- x$constraints
@@ -224,8 +224,9 @@
       }
     }
   }
-  cat("Number of disabled constraints:", nconstraints - n.enabled.constraints, "\n")
+  
   if((nconstraints - n.enabled.constraints) > 0){
+    #cat("Number of disabled constraints:", nconstraints - n.enabled.constraints, "\n")
     cat("Disabled constraint types\n")
     constraints <- x$constraints
     nconstraints <- length(constraints)
@@ -253,9 +254,9 @@
   }
   
   # Objectives
-  cat("\nObjectives\n")
   nobjectives <- length(x$objectives)
   if(nobjectives > 0){
+    cat("\nObjectives:\n")
     # logical vector of enabled objectives
     enabled.objectives <- which(sapply(x$objectives, function(x) x$enabled))
     n.enabled.objectives <- ifelse(length(enabled.objectives) > 0, length(enabled.objectives), 0)
@@ -265,17 +266,18 @@
   }
   # character vector of objective names
   names.objectives <- sapply(x$objectives, function(x) x$name)
-  cat("Number of objectives:", nobjectives, "\n")
-  cat("Number of enabled objectives:", n.enabled.objectives, "\n")
+  #cat("Number of objectives:", nobjectives, "\n")
+  #cat("Number of enabled objectives:", n.enabled.objectives, "\n")
   if(n.enabled.objectives > 0){
     cat("Enabled objective names\n")
     for(name in names.objectives[enabled.objectives]) {
       cat("\t\t-", name, "\n")
     }
   }
-  cat("Number of disabled objectives:", nobjectives - n.enabled.objectives, "\n")
+  
   if((nobjectives - n.enabled.objectives) > 0){
-    cat("Disabled objective types\n")
+    #cat("Number of disabled objectives:", nobjectives - n.enabled.objectives, "\n")
+    cat("Disabled objective names\n")
     for(name in setdiff(names.objectives, names.objectives[enabled.objectives])) {
       cat("\t\t-", name, "\n")
     }



More information about the Returnanalytics-commits mailing list