1

I've been trying to trouble shoot an error in R notebook where the R chunks execute correctly, but when I try to preview the notebook, I get the following error:

Error creating notebook: values must be length 3, but FUN(X[[1]])result is length 1. See line 31.

The code that creates the error is the Friedman analysis of my data (which uses agricolae package).

Here are the chunks that execute correctly and that are used for the Friedman analysis (these are code chunks from my R notebook, but I've omitted the {r} and back ticks required in the notebook for the purpose of this question):

Package installation

if(!require(agricolae))
{
print("You are missing the package 'agricolae', we will now try to install it...")
install.packages("agricolae")
library(agricolae)
}

Data frame creation


WineTasting <- data.frame(
  Taste = c(5.40, 5.50, 5.55,
            5.85, 5.70, 5.75,
            5.20, 5.60, 5.50,
            5.55, 5.50, 5.40,
            5.90, 5.85, 5.70,
            5.45, 5.55, 5.60,
            5.40, 5.40, 5.35,
            5.45, 5.50, 5.35,
            5.25, 5.15, 5.00,
            5.85, 5.80, 5.70,
            5.25, 5.20, 5.10,
            5.65, 5.55, 5.45,
            5.60, 5.35, 5.45,
            5.05, 5.00, 4.95,
            5.50, 5.50, 5.40,
            5.45, 5.55, 5.50,
            5.55, 5.55, 5.35,
            5.45, 5.50, 5.55,
            5.50, 5.45, 5.25,
            5.65, 5.60, 5.40,
            5.70, 5.65, 5.55,
            6.30, 6.30, 6.25),
  Wine = factor(rep(c("Wine A", "Wine B", "Wine C"), 22)),
  Taster = factor(rep(1:22, rep(3, 22))))

head(WineTasting)

Friedman test

This is where the error lies:

Friedmantest <- with(WineTasting,friedman(Taster,Wine,Taste,alpha=0.05, group=TRUE,console=TRUE))

The Friedmantest code works fine and prints the correct results to the console, but fails to preview in the notebook, generating the error.

I've tried running this with different data sets, to no avail (I get the same error message). Google didn't really yield any helpful results and it doesn't seem like this error has been discussed in Stackoverflow before. Any help would be appreciated.

Minimal reproducible example

library(agricolae)
WineTasting <- data.frame(
  Taste = c(5.40, 5.50, 5.55,
            5.85, 5.70, 5.75,
            5.20, 5.60, 5.50,
            5.55, 5.50, 5.40,
            5.90, 5.85, 5.70,
            5.45, 5.55, 5.60,
            5.40, 5.40, 5.35,
            5.45, 5.50, 5.35,
            5.25, 5.15, 5.00,
            5.85, 5.80, 5.70,
            5.25, 5.20, 5.10,
            5.65, 5.55, 5.45,
            5.60, 5.35, 5.45,
            5.05, 5.00, 4.95,
            5.50, 5.50, 5.40,
            5.45, 5.55, 5.50,
            5.55, 5.55, 5.35,
            5.45, 5.50, 5.55,
            5.50, 5.45, 5.25,
            5.65, 5.60, 5.40,
            5.70, 5.65, 5.55,
            6.30, 6.30, 6.25),
  Wine = factor(rep(c("Wine A", "Wine B", "Wine C"), 22)),
  Taster = factor(rep(1:22, rep(3, 22))))

Friedmantest <- with(WineTasting,friedman(Taster,Wine,Taste,alpha=0.05, group=TRUE,console=TRUE))
KatP
  • 45
  • 7
  • Please create a [mre]. That way others can copy&paste your code to reproduce and hopefully solve the issue. – Ralf Stubner Aug 14 '19 at 09:46
  • I've added a minimal reproducible example for you now. – KatP Aug 14 '19 at 10:15
  • 1
    Thanks for the example, though that is not what I asked for. The R code works on its own, but it fails in a RNotebook. Try to remove `console = TRUE`. It seems RNotebook does not like that. – Ralf Stubner Aug 14 '19 at 10:30
  • 1
    Alternatively, you could use a normal R markdown document (i.e. `output: html_document` instead of `output: html_notbook`). – Ralf Stubner Aug 14 '19 at 10:36
  • Thank you for your help! Sorry, I'm not sure what you asked me for then, what code would you need exactly?. Yes, the R code works on its own, but not in a notebook. That is exactly the problem I have. I've tried removing the `console=TRUE` argument, but now it's just printing the `Friedmantest` code chunk to the notebook, but not its output. I've tried printing it as html notebook, leaving the `console=TRUE` argument in the code and that works well. Thank you for that. Is there a way though to make it work in the notebook at all? – KatP Aug 14 '19 at 13:54
  • 1
    Ah, I made it work. I removed the `console=TRUE` argument, like you said and just added a `print (Friedmantest)` statement. The notebook preview now prints the output of the Friedman Test. Thank you for your help! – KatP Aug 14 '19 at 14:11
  • You could also put parentheses around the assignment, making the printing automatic. I had the impression that the print output wasn’t has nice, though. One could consider that a bug in the package. – Ralf Stubner Aug 14 '19 at 14:14
  • From the comments it seems you have the solution, please consider adding your solution as an answer. – zx8754 Jan 30 '20 at 11:43

1 Answers1

0

To make it work I removed the console=TRUE argument added a print(Friedmantest)statement. The notebook preview now prints the output of the Friedman Test. The correct code now looks like this:

Friedmantest <- with(WineTasting,friedman(Taster,Wine,Taste,alpha=0.05, group=TRUE))
print(Friedmantest)

KatP
  • 45
  • 7