0

I am running this code:

max.print <- getOption('max.print')
options(max.print=nrow(countryaccepted) * ncol(countryaccepted))
sink(file.txt, append=TRUE, type="out")
cat("*************************\n")
cat("F-Test and T-Test Results")
as.array(HypothesisTesting)
cat("\n\n\n")
sink()
options(max.print=max.print)

The variable "HypothesisTesting" is a 3D array having dimensions 2 x 2 x 2 and contains values of type "double".

I am getting only following result in the file when I run the code via "Source"

*************************
F-Test and T-Test Results

But when I run it in "Console", I get following result saved in the file:

*************************
F-Test and T-Test Results

, , TTest

         H0 Accepted H0 Rejected
Ho True     98.68938    0.970427
H0 False     8.62801    1.310620

, , FTest

         H0 Accepted H0 Rejected
Ho True     100.0000     4.22076
H0 False     7.50504     0.00000

Why is the result not getting saved via source and why is it getting saved only via console?

Where am I wrong?

1 Answers1

0

You need to use print() if you want to save the (console) output of an object via function or source.

*************************
F-Test and T-Test Results
, , 1

     [,1] [,2]
[1,] 0.01 0.01
[2,] 0.01 0.01

, , 2

     [,1] [,2]
[1,] 0.01 0.01
[2,] 0.01 0.01

Code

arr <- array(0.01, dim=c(2, 2, 2))

max.print <- getOption('max.print')
options(max.print = 100)

sink("file.txt", append = TRUE, type = "out")
cat("*************************\n")
cat("F-Test and T-Test Results\n")
print(as.array(arr))                                   # wrap output into print()
cat("\n\n\n")
sink()
options(max.print = max.print)
Roman
  • 4,744
  • 2
  • 16
  • 58