1

I am trying to cluster my data using hclust and print to a html using Rmarkdown.

When I call hclust from the console or in an .Rmd, the clustering occurs perfectly exactly as I want it. But additionally, I receive the error message:

must have n >= 2 objects to cluster

I can force knitr to continue processing using error=TRUE, but the error is there and the value not assigned.

tree = hclust(dist(t(sample_matrix), method = "euclidean"), method = "complete")

I want to process object tree further I have also tried "fixing" the error by using try(...,silent=TRUE). It works as long as I don't need to assign the returned value. Also tryCatch doesn't seem to help with this (correct me if I'm wrong).

How can I suppress this error message in my Rmarkdown?

JelenaČuklina
  • 3,574
  • 2
  • 22
  • 35

1 Answers1

1

I tried tryCatch and it appears to work.

---
title: "Untitled"
author: "Roman Luštrik"
date: "23. november 2015"
output: html_document
---

```{r}
x <- tryCatch(simpleError("eror mesiđ"), error = function(e) e)
```

```{r}
plot(runif(100), runif(100))
```

enter image description here

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
  • Thanks, @Roman Luštrik, this is not exactly what's the problem. The function call ends with error, but I need to use further on the value returned by this function. In console everything works seamlessly. – JelenaČuklina Nov 24 '15 at 09:59
  • @Jelena-bioinf you can have `tryCatch` return anything you want (other than the true result as if no error had occurred, obviously). – Roman Luštrik Nov 24 '15 at 21:54