Home > Back-end >  Error while knitting R-markdown to pdf: must be a finite number
Error while knitting R-markdown to pdf: must be a finite number

Time:01-08

Knitting my File produces the error message down below:

Picture of Error

This is how my File starts:

Start of file

Unfortunately, I couldn't try anything as I have no idea what the error message has to do with the displayed information.

I hope to knit the document to a pdf once this error has been removed.

My code:

library(plotrix) 
p6<-pie3D(rawdata8.2$rawdata8.1, 
          col = hcl.colors(length(data), "Spectral"),
          radius = 1.7, 
          theta = 0.25,  
          shade = 0.5,
          height = 0.3,
          start = pi/1.25, 
          explode = 0.2)
title("Anzahl Ankünfte nach Herkunftsland der Touristen 2020" )

CodePudding user response:

The problem is probably in your 3Dpie and not in the fact that you are knitting to pdf. Please consider checking pie3D documentation. And try to run the code of that particular chunk in your console.

Check this example for instance: did you provide both values and labels for your pie-chart? Does it help to set the radius back to 1? Not sure if it can be higher in user units? Have you defined pi somewhere? Or do you need to call it from a math package?

These are some ideas. I hope it helps. This problem might also help.

CodePudding user response:

The most obvious problem is that you are probably asking for a palette of length 1:

hcl.colors(1, "Spectral")

Error in seq.int(1, by = -2/(n - 1), length.out = n2) : 'by' must be a finite number

This happens because hcl.colors tries to set up a step size -2/(n-1), which is infinite if n==1.

Guessing beyond this what's going on: unless you have explicitly defined an object called data in your workspace, R will find the built-in function data(): length(data) is 1 (as it seems all functions have length 1 - not quite sure what the logic is here ...)

Also keep in mind that if you have a data frame df, length(df) will give you the number of columns — you would need nrow(df) to get the number of rows ...

  • Related