R markdown does not find a function

When I run a script in R, there is no error, and everything works.

    library(tweedie)
    data_tweedie <- glm(y ~ ., data = data, family = tweedie(var.power = data_tw$p.max, link.power = 0))

But when I knit the R markdown with the same r section, it gives me an Error

enter image description here

Is it some kind of a bug of the package?

here is a reproducible example

library(tweedie)
x <- seq(0,10,1)
y <- seq(0,20,2)
data <- as.data.frame(y, x)
Model <- glm(y ~ x, data = data, family = tweedie(var.power = 1.5, link.power = 0)) 

When I run it just in console of R studio, there is no problem. But when I include the same exact piece in the R markdown document, it gives an error

When you knit in RStudio IDE, it will run in another clean session. When you have this issue, it means something is missing, probably because object if from somewhere else.

tweedie library does not have a tweedie() function. If that works for you in console, you must have defined it in your global environment.

This does not work for me in R console

library(tweedie)
x <- seq(0,10,1)
y <- seq(0,20,2)
data <- as.data.frame(y, x)
#> Warning in as.data.frame.numeric(y, x): 'row.names' is not a character vector of
#> length 11 -- omitting it. Will be an error!
Model <- glm(y ~ x, data = data, family = tweedie(var.power = 1.5, link.power = 0))
#> Error in tweedie(var.power = 1.5, link.power = 0): could not find function "tweedie"
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.