function evaluation of Shapiro-Wilk test

Hi. Normally, I'd urge the reprex described in the FAQ: What's a reproducible example (`reprex`) and how do I do one? Using a reprex, complete with representative data will attract quicker and more answers.

This code is simple enough not to need one though.

seed <- 1234
x1 <-rnorm(10, mean = 5, sd = 3)
x2 <- runif(10, min = 2, max = 4)
shapiro.test(x1)
#> 
#>  Shapiro-Wilk normality test
#> 
#> data:  x1
#> W = 0.73903, p-value = 0.002624
shapiro.test(x2)
#> 
#>  Shapiro-Wilk normality test
#> 
#> data:  x2
#> W = 0.93302, p-value = 0.4782

SWtest <- function(x) {
cat("S-W statistic for",
shapiro.test(x)$data.name,"is",
round(shapiro.test(x)$statistic,4),
"with p-value =",
round(shapiro.test(x)$p.value,4),"\n")
}
outcome <- SWtest(x1)
#> S-W statistic for x is 0.739 with p-value = 0.0026
outcome
#> NULL
plain <- shapiro.test(x1)
plain
#> 
#>  Shapiro-Wilk normality test
#> 
#> data:  x1
#> W = 0.73903, p-value = 0.002624
str(plain)
#> List of 4
#>  $ statistic: Named num 0.739
#>   ..- attr(*, "names")= chr "W"
#>  $ p.value  : num 0.00262
#>  $ method   : chr "Shapiro-Wilk normality test"
#>  $ data.name: chr "x1"
#>  - attr(*, "class")= chr "htest"

Created on 2020-04-04 by the reprex package (v0.3.0)

Illustrates the issue. SWtest only sends its output to stdout. It can't be assigned to an object, as written.

shapiro.test(), on the other hand, can be easily captured.

The implications for rewriting shapiro.test should be pretty clear--building it up from plain[1:4] with paste as one option.

If you get stuck, of course, please come on back.