How to find the source code of R package functions

Viewed 30

Context

I'm trying to put a function written by someone else in my own R package but I'm having some problems.

Question

The problem is that the code that calculates std.error gives an error, but when I load the coxme package, the error goes away.

I can't use library(coxme) when writing R package functions. Please tell me how I can successfully calculate std.error.

Reproduciable code

A reproducible example is as follows:

library(survival)
# fit a coxme model
fit <- coxme::coxme(Surv(time, status) ~ ph.ecog + age + (1|inst), lung)

# estimate,nvar and nfrail are for calculating std.error
estimate <- coxme::fixef(fit)
nvar <- base::length(estimate)
nfrail <- base::nrow(fit$var) - nvar
std.error <- base::sqrt(diag(fit$var)[nfrail + 1:nvar])
# Error in as.integer(x) : 
#  cannot coerce type 'S4' to vector of type 'integer'

When the coxme package is loaded, std.error can be successfully computed.

library(coxme)
std.error <- base::sqrt(diag(fit$var)[nfrail + 1:nvar]) # Running successfully

What I've done

  1. I thought that the diag() function might come from the coxme package, but after I asked this question at stackoverflow, I found out that the diag() function in the coxme package is from the base package.

  2. For the code to calculate std.error I refer to this URL: https://stackoverflow.com/a/43720261/11636376

0 Answers
Related