Knitr renders graphics, although they shouldn't

I am using RStudio: Version 1.0.136 and I am trying to understand why knitr displays histograms associated with the commands below. Any help is appreciated.

min_ct<-as.numeric(min(hist(myfdata[myfdata$slope>low & myfdata$slope<up, ]$dy, breaks = bi)$counts))

      

Screenshot of 4 rendered graphics objects that are not explicitly generated.

enter image description here

+3


source to share


1 answer


This is not a problem knitr

. The call hist

causes the histogram to be displayed even if you assign the output to a variable. In the console, try it x = hist(rnorm(100))

. What is stored in the variable is a list with the data used to generate the histogram, but the histogram is still being printed.

To create bins without printing a histogram, use the function cut

to create bins, then use table

bin to count the number of values. Eg table(cut(rnorm(100), breaks=seq(-3,3,0.5)))

.



cut

has parameters that affect how it assigns cells, so check out help ( ?cut

) for more information. In particular, pay attention to the arguments right

and include.lowest

.

+3


source







All Articles