I've noticed that there may be a new feature on the latest version of R Studio on Ubuntu 22.04, but I can't seem to find any news about it and I don't know what to search on Google to understand it more.
Here is my R Studio Version
RStudio 2023.09.1+494 "Desert Sunflower" Release (cd7011dce393115d3a7c3db799dda4b1c7e88711, 2023-10-16) for Ubuntu Jammy
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) rstudio/2023.09.1+494 Chrome/116.0.5845.190 Electron/26.2.4 Safari/537.36
As you can see here on R version 4.3.1 installed by ASDF, I am able to see the internal lmer comments when I run the command through the console in R-Studio
lme4::lmer
#> function(formula, data=NULL, REML = TRUE,
#> control = lmerControl(), start = NULL
#> , verbose = 0L
#> , subset, weights, na.action, offset
#> , contrasts = NULL
#> , devFunOnly=FALSE
#> )
#> ## , ...)
#> {
#> mc <- mcout <- match.call()
#> missCtrl <- missing(control)
#> ## see functions in modular.R for the body ..
#> if (!missCtrl && !inherits(control, "lmerControl")) {
#> if(!is.list(control)) stop("'control' is not a list; use lmerControl()")
#> ## back-compatibility kluge
#> warning("passing control as list is deprecated: please use lmerControl() instead",
#> immediate.=TRUE)
#> control <- do.call(lmerControl, control)
#> }
#> ## if (!is.null(list(...)[["family"]])) {
#> ## warning("calling lmer with 'family' is deprecated; please use glmer() instead")
#> ## mc[[1]] <- quote(lme4::glmer)
#> ## if(missCtrl) mc$control <- glmerControl()
#> ## return(eval(mc, parent.frame(1L)))
#> ## }
#> mc$control <- control ## update for back-compatibility kluge
#>
#> ## https://github.com/lme4/lme4/issues/50
#> ## parse data and formula
#> mc[[1]] <- quote(lme4::lFormula)
#> lmod <- eval(mc, parent.frame(1L))
#> mcout$formula <- lmod$formula
#> lmod$formula <- NULL
#>
#> ## create deviance function for covariance parameters (theta)
#> devfun <- do.call(mkLmerDevfun,
#> c(lmod,
#> list(start=start, verbose=verbose, control=control)))
#> if (devFunOnly) return(devfun)
#> ## optimize deviance function over covariance parameters
#> if (identical(control$optimizer,"none"))
#> stop("deprecated use of optimizer=='none'; use NULL instead")
#> opt <- if (length(control$optimizer)==0) {
#> s <- getStart(start, environment(devfun)$pp)
#> list(par=s,fval=devfun(s),
#> conv=1000,message="no optimization")
#> } else {
#> optimizeLmer(devfun, optimizer = control$optimizer,
#> restart_edge = control$restart_edge,
#> boundary.tol = control$boundary.tol,
#> control = control$optCtrl,
#> verbose=verbose,
#> start=start,
#> calc.derivs=control$calc.derivs,
#> use.last.params=control$use.last.params)
#> }
#> cc <- checkConv(attr(opt,"derivs"), opt$par,
#> ctrl = control$checkConv,
#> lbound = environment(devfun)$lower)
#> mkMerMod(environment(devfun), opt, lmod$reTrms, fr = lmod$fr,
#> mc = mcout, lme4conv=cc) ## prepare output
#> }
#> <bytecode: 0x5586fbfccf60>
#> <environment: namespace:lme4>
Created on 2023-11-03 with reprex v2.0.2
But when I run R in my konsole terminal and (using most packages in general) I am unable to see the internal comments in the function
lme4::lmer
#> function (formula, data = NULL, REML = TRUE, control = lmerControl(),
#> start = NULL, verbose = 0L, subset, weights, na.action, offset,
#> contrasts = NULL, devFunOnly = FALSE)
#> {
#> mc <- mcout <- match.call()
#> missCtrl <- missing(control)
#> if (!missCtrl && !inherits(control, "lmerControl")) {
#> if (!is.list(control))
#> stop("'control' is not a list; use lmerControl()")
#> warning("passing control as list is deprecated: please use lmerControl() instead",
#> immediate. = TRUE)
#> control <- do.call(lmerControl, control)
#> }
#> mc$control <- control
#> mc[[1]] <- quote(lme4::lFormula)
#> lmod <- eval(mc, parent.frame(1L))
#> mcout$formula <- lmod$formula
#> lmod$formula <- NULL
#> devfun <- do.call(mkLmerDevfun, c(lmod, list(start = start,
#> verbose = verbose, control = control)))
#> if (devFunOnly)
#> return(devfun)
#> if (identical(control$optimizer, "none"))
#> stop("deprecated use of optimizer=='none'; use NULL instead")
#> opt <- if (length(control$optimizer) == 0) {
#> s <- getStart(start, environment(devfun)$pp)
#> list(par = s, fval = devfun(s), conv = 1000, message = "no optimization")
#> }
#> else {
#> optimizeLmer(devfun, optimizer = control$optimizer, restart_edge = control$restart_edge,
#> boundary.tol = control$boundary.tol, control = control$optCtrl,
#> verbose = verbose, start = start, calc.derivs = control$calc.derivs,
#> use.last.params = control$use.last.params)
#> }
#> cc <- checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,
#> lbound = environment(devfun)$lower)
#> mkMerMod(environment(devfun), opt, lmod$reTrms, fr = lmod$fr,
#> mc = mcout, lme4conv = cc)
#> }
#> <bytecode: 0x564ec480cba0>
#> <environment: namespace:lme4>
Created on 2023-11-03 with reprex v2.0.2
I was wondering if there was a way to always show the internal comments including debugging? It'd just be so helpful to debug functions with the comments already included... However, even running through R Studio, I see that the display of internal comments is inconsistent.
For example, this shows no comments even though it probably has internal comments based on this Github repository
lm
#> function (formula, data, subset, weights, na.action, method = "qr",
#> model = TRUE, x = FALSE, y = FALSE, qr = TRUE, singular.ok = TRUE,
#> contrasts = NULL, offset, ...)
#> {
#> ret.x <- x
#> ret.y <- y
#> cl <- match.call()
#> mf <- match.call(expand.dots = FALSE)
#> m <- match(c("formula", "data", "subset", "weights", "na.action",
#> "offset"), names(mf), 0L)
#> mf <- mf[c(1L, m)]
#> mf$drop.unused.levels <- TRUE
#> mf[[1L]] <- quote(stats::model.frame)
#> mf <- eval(mf, parent.frame())
#> if (method == "model.frame")
#> return(mf)
#> else if (method != "qr")
#> warning(gettextf("method = '%s' is not supported. Using 'qr'",
#> method), domain = NA)
#> mt <- attr(mf, "terms")
#> y <- model.response(mf, "numeric")
#> w <- as.vector(model.weights(mf))
#> if (!is.null(w) && !is.numeric(w))
#> stop("'weights' must be a numeric vector")
#> offset <- model.offset(mf)
#> mlm <- is.matrix(y)
#> ny <- if (mlm)
#> nrow(y)
#> else length(y)
#> if (!is.null(offset)) {
#> if (!mlm)
#> offset <- as.vector(offset)
#> if (NROW(offset) != ny)
#> stop(gettextf("number of offsets is %d, should equal %d (number of observations)",
#> NROW(offset), ny), domain = NA)
#> }
#> if (is.empty.model(mt)) {
#> x <- NULL
#> z <- list(coefficients = if (mlm) matrix(NA_real_, 0,
#> ncol(y)) else numeric(), residuals = y, fitted.values = 0 *
#> y, weights = w, rank = 0L, df.residual = if (!is.null(w)) sum(w !=
#> 0) else ny)
#> if (!is.null(offset)) {
#> z$fitted.values <- offset
#> z$residuals <- y - offset
#> }
#> }
#> else {
#> x <- model.matrix(mt, mf, contrasts)
#> z <- if (is.null(w))
#> lm.fit(x, y, offset = offset, singular.ok = singular.ok,
#> ...)
#> else lm.wfit(x, y, w, offset = offset, singular.ok = singular.ok,
#> ...)
#> }
#> class(z) <- c(if (mlm) "mlm", "lm")
#> z$na.action <- attr(mf, "na.action")
#> z$offset <- offset
#> z$contrasts <- attr(x, "contrasts")
#> z$xlevels <- .getXlevels(mt, mf)
#> z$call <- cl
#> z$terms <- mt
#> if (model)
#> z$model <- mf
#> if (ret.x)
#> z$x <- x
#> if (ret.y)
#> z$y <- y
#> if (!qr)
#> z$qr <- NULL
#> z
#> }
#> <bytecode: 0x557b5fdc1f60>
#> <environment: namespace:stats>
Created on 2023-11-03 with reprex v2.0.2