Pārlūkot izejas kodu

New console output function

Deben Oldert 9 gadi atpakaļ
vecāks
revīzija
01d9891d47
4 mainītis faili ar 27 papildinājumiem un 6 dzēšanām
  1. 20 0
      code/functions.R
  2. 3 3
      code/head.R
  3. 2 1
      code/main.R
  4. 2 2
      code/state.R

+ 20 - 0
code/functions.R

@@ -54,3 +54,23 @@ group <- function(a, n=1){
     return(l_)
   }
 }
+
+# Console.NewLine. Write string to console and appends a new line
+#   a => string to output
+#
+# Returns => void, but prints in console with appended newline
+
+Console.NewLine <- function(a){
+  Console.Line(a)
+  cat("\n")
+}
+
+# Console.Line. Write string to console
+#   a => string to output
+#
+# Returns => void, but prints in console
+
+Console.Line <- function(a){
+  cat(a)
+}
+

+ 3 - 3
code/head.R

@@ -1,4 +1,4 @@
-print("START ANALYZING HEAD")
+Console.NewLine("START ANALYZING HEAD")
 color <- c("red", "blue", "blue", "green")
 
 #Plot graph
@@ -32,6 +32,6 @@ for(i in patient$WALKING){
 remove(i)
 remove(prob_)
 # Print out possible fall chance
-print(paste("FALL CHANCE BASED ON STEPS: ", as.character(specify_decimal(100-(mean(WALK$probability)*100), 2)), "%", sep = ""))
+Console.NewLine(paste("FALL CHANCE BASED ON STEPS: ", as.character(specify_decimal(100-(mean(WALK$probability)*100), 2)), "%", sep = ""))
 
-print("DONE ANALYZING HEAD")
+Console.NewLine("DONE ANALYZING HEAD")

+ 2 - 1
code/main.R

@@ -1,5 +1,6 @@
 suppressMessages(library(dplyr))
 suppressMessages(library(stringr))
+suppressMessages(library(crayon))
 
 source("code/functions.R")
 
@@ -42,7 +43,7 @@ remove(y)
 remove(z)
 remove(cnv_)
 
-print("DATA PREPERATION DONE")
+Console.NewLine("DATA PREPERATION DONE")
 
 source("code/state.R")
 

+ 2 - 2
code/state.R

@@ -70,7 +70,7 @@ DATA <- DATA[complete.cases(DATA),]
 rownames(DATA) <- 1:nrow(DATA)
 DATA$index = as.integer(rownames(DATA))
 
-print("STATE CALCULATION DONE")
+Console.NewLine("STATE CALCULATION DONE")
 
 # USE PATIENT ENVIRONMENT
 source("code/patient.R")
@@ -108,7 +108,7 @@ remove(yPredicted)
 
 plot(POINTS$probability, type = "l")
 
-print("FILLING PATIENT CLASS DONE")
+Console.NewLine("FILLING PATIENT CLASS DONE")
 
 # http://stats.stackexchange.com/questions/30975/how-to-add-non-linear-trend-line-to-a-scatter-plot-in-r
 # http://www.mathsisfun.com/geometry/parabola.html