Re: [R-br] Como ver o que uma função faz
Tem situações que em que é mais prático olhar o fonte no GitHub. O CRAN mantém os repositórios em formato "somente leitura". O interessante é que você pode usar o motor de busca do GitHub. Assim ele te retorna os arquivos do repositório que batem com um termo de busca. O rms possui o repositórios somente leitura do CRAN e o mantido autor: https://github.com/cran/rms https://github.com/harrelfe/rms À disposição. Walmes. ___ R-br mailing list R-br@listas.c3sl.ufpr.br https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forne�a c�digo m�nimo reproduz�vel.
Re: [R-br] Como ver o que uma função faz
Se o pacote for o rms basta baixar o código fonte e abrir a pasta R/ http://cran-r.c3sl.ufpr.br/src/contrib/rms_5.1-1.tar.gz "May the source be with you" --- Fernando de Pol Mayer Laboratório de Estatística e Geoinformação - LEG Departamento de Estatística - DEST Universidade Federal do Paraná - UFPR URL: http://leg.ufpr.br/~fernandomayer e-mail: fernando.mayer [@] {gmail.com, ufpr.br} 2017-09-01 21:56 GMT-03:00 Cesar Rabak via R-br: > Pedro, > > Acho que nesse caso a forma mais prática seria você baixar o código do > pacote e ver a dita cuja diretamente. . . > > > 2017-09-01 9:38 GMT-03:00 Pedro Emmanuel Alvarenga Americano do Brasil via > R-br : > >> library(rms) >> rms:::Function.cph >> rms:::Function.rms >> >> Pacote errado e é uma função aninhada em outra. >> >> Pedro Brasil >> >> Em 25 de agosto de 2017 14:53, Tiago Fragoso >> escreveu: >> >>> Olá, >>> >>> Essa função não aparece nem pra mim nem pro Marcus quando usamos >>> methods(), capaz que ela não esteja em versões posteriores do Hmisc. >>> >>> O asterisco na saida do methods() indica uma função não exportada. Nesse >>> caso, Hmisc:::Function.cph deveria achar a função. Note os três ":". >>> >>> 2017-08-25 14:10 GMT-03:00 Pedro Emmanuel Alvarenga Americano do Brasil >>> via R-br : >>> Ei Marcus, No meu caso, eu gostaria de ver a Function.cph, mas ela aparece com um asterisco que eu não sei o que é. Então... > Function.cph Error: object 'Function.cph' not found > Function.cph* + E a função não aparece. Pedro Brasil Em 25 de agosto de 2017 13:37, Marcus Nunes escreveu: > Use `methods` para encontrar os métodos da função desejada: > > > methods(Function) > [1] Function.areg.boot Function.transcan > see '?methods' for accessing help and source code > > Esta função tem dois métodos associados a ela: Function.areg.boot e > Function.transcan. Agora é só pedir pra ver o código fonte do método que > te > interessa: > > > Function.areg.boot > function (object, type = c("list", "individual"), ytype = > c("transformed", > "inverse"), prefix = ".", suffix = "", pos = -1, ...) > { > type <- match.arg(type) > ytype <- match.arg(ytype) > if (missing(type) && !(missing(prefix) & missing(suffix) & > missing(pos))) > type <- "individual" > fit <- object$fit > k <- length(fit) > nam <- names(fit) > g <- vector("list", k) > xtype <- object$xtype > typey <- object$ytype > catl <- object$cat.levels > names(g) <- nam > for (i in 1:k) { > typ <- if (i == 1) > typey > else xtype[i - 1] > if (typ == "c") { > if (i == 1 && ytype == "inverse") > stop("currently does not handle ytype=\\"inverse\\" > when y is categorical") > h <- function(x, trantab) { > if (is.factor(x)) > x <- as.character(x) > trantab[x] > } > w <- fit[[i]]$y > names(w) <- catl[[nam[i]]] > formals(h) <- list(x = numeric(0), trantab = w) > } > else { > h <- function(x, trantab) { > s <- !is.na(x) > res <- rep(NA, length(x)) > res[s] <- approxExtrap(trantab, xout = x[s])$y > res > } > fiti <- fit[[i]] > formals(h) <- list(x = numeric(0), trantab = if (i == > 1 && ytype == "transformed") list(x = fiti[[2]], > y = fiti[[1]]) else fiti) > } > g[[i]] <- h > } > if (type == "list") > return(g) > fun.name <- paste(prefix, nam, suffix, sep = "") > for (i in 1:k) assign(fun.name[i], g[[i]], pos = pos) > invisible(fun.name) > } > > > > > > > > -- > Marcus Nunes > Professor Adjunto > Universidade Federal do Rio Grande do Norte > Centro de Ciências Exatas e da Terra > Departamento de Estatística > Laboratório de Estatística Aplicada > marcus.nu...@ccet.ufrn.br > http://marcusnunes.me/ > > > 2017-08-25 13:21 GMT-03:00 Pedro Emmanuel Alvarenga Americano do > Brasil via R-br : > >> Amigos de R, >> >> Gostaria de poder ver a sequencia de operações que uma função faz. Na >> maioria das funções, basta digitar o nome da função no console, por >> exemplo >> >> > trimws >> function (x, which = c("both", "left", "right")) >> { >> which <- match.arg(which) >>
Re: [R-br] Como ver o que uma função faz
Pedro, Acho que nesse caso a forma mais prática seria você baixar o código do pacote e ver a dita cuja diretamente. . . 2017-09-01 9:38 GMT-03:00 Pedro Emmanuel Alvarenga Americano do Brasil via R-br: > library(rms) > rms:::Function.cph > rms:::Function.rms > > Pacote errado e é uma função aninhada em outra. > > Pedro Brasil > > Em 25 de agosto de 2017 14:53, Tiago Fragoso > escreveu: > >> Olá, >> >> Essa função não aparece nem pra mim nem pro Marcus quando usamos >> methods(), capaz que ela não esteja em versões posteriores do Hmisc. >> >> O asterisco na saida do methods() indica uma função não exportada. Nesse >> caso, Hmisc:::Function.cph deveria achar a função. Note os três ":". >> >> 2017-08-25 14:10 GMT-03:00 Pedro Emmanuel Alvarenga Americano do Brasil >> via R-br : >> >>> Ei Marcus, >>> >>> No meu caso, eu gostaria de ver a Function.cph, mas ela aparece com um >>> asterisco que eu não sei o que é. Então... >>> >>> > Function.cph >>> Error: object 'Function.cph' not found >>> > Function.cph* >>> + >>> >>> E a função não aparece. >>> >>> Pedro Brasil >>> >>> Em 25 de agosto de 2017 13:37, Marcus Nunes >>> escreveu: >>> Use `methods` para encontrar os métodos da função desejada: > methods(Function) [1] Function.areg.boot Function.transcan see '?methods' for accessing help and source code Esta função tem dois métodos associados a ela: Function.areg.boot e Function.transcan. Agora é só pedir pra ver o código fonte do método que te interessa: > Function.areg.boot function (object, type = c("list", "individual"), ytype = c("transformed", "inverse"), prefix = ".", suffix = "", pos = -1, ...) { type <- match.arg(type) ytype <- match.arg(ytype) if (missing(type) && !(missing(prefix) & missing(suffix) & missing(pos))) type <- "individual" fit <- object$fit k <- length(fit) nam <- names(fit) g <- vector("list", k) xtype <- object$xtype typey <- object$ytype catl <- object$cat.levels names(g) <- nam for (i in 1:k) { typ <- if (i == 1) typey else xtype[i - 1] if (typ == "c") { if (i == 1 && ytype == "inverse") stop("currently does not handle ytype=\\"inverse\\" when y is categorical") h <- function(x, trantab) { if (is.factor(x)) x <- as.character(x) trantab[x] } w <- fit[[i]]$y names(w) <- catl[[nam[i]]] formals(h) <- list(x = numeric(0), trantab = w) } else { h <- function(x, trantab) { s <- !is.na(x) res <- rep(NA, length(x)) res[s] <- approxExtrap(trantab, xout = x[s])$y res } fiti <- fit[[i]] formals(h) <- list(x = numeric(0), trantab = if (i == 1 && ytype == "transformed") list(x = fiti[[2]], y = fiti[[1]]) else fiti) } g[[i]] <- h } if (type == "list") return(g) fun.name <- paste(prefix, nam, suffix, sep = "") for (i in 1:k) assign(fun.name[i], g[[i]], pos = pos) invisible(fun.name) } -- Marcus Nunes Professor Adjunto Universidade Federal do Rio Grande do Norte Centro de Ciências Exatas e da Terra Departamento de Estatística Laboratório de Estatística Aplicada marcus.nu...@ccet.ufrn.br http://marcusnunes.me/ 2017-08-25 13:21 GMT-03:00 Pedro Emmanuel Alvarenga Americano do Brasil via R-br : > Amigos de R, > > Gostaria de poder ver a sequencia de operações que uma função faz. Na > maioria das funções, basta digitar o nome da função no console, por > exemplo > > > trimws > function (x, which = c("both", "left", "right")) > { > which <- match.arg(which) > mysub <- function(re, x) sub(re, "", x, perl = TRUE) > if (which == "left") > return(mysub("^[ \t\r\n]+", x)) > if (which == "right") > return(mysub("[ \t\r\n]+$", x)) > mysub("[ \t\r\n]+$", mysub("^[ \t\r\n]+", x)) > } > > > > No entanto, algumas funções não seguem essa regra e eu não sei como > fazer. Por exemplo > > library(Hmisc) > > Function > function (object, ...) > UseMethod("Function") > > > Alguma dica pra conseguir enxergar as operações dessa função? > > Abraço forte, > > Pedro Brasil
Re: [R-br] Como ver o que uma função faz
library(rms) rms:::Function.cph rms:::Function.rms Pacote errado e é uma função aninhada em outra. Pedro Brasil Em 25 de agosto de 2017 14:53, Tiago Fragosoescreveu: > Olá, > > Essa função não aparece nem pra mim nem pro Marcus quando usamos > methods(), capaz que ela não esteja em versões posteriores do Hmisc. > > O asterisco na saida do methods() indica uma função não exportada. Nesse > caso, Hmisc:::Function.cph deveria achar a função. Note os três ":". > > 2017-08-25 14:10 GMT-03:00 Pedro Emmanuel Alvarenga Americano do Brasil > via R-br : > >> Ei Marcus, >> >> No meu caso, eu gostaria de ver a Function.cph, mas ela aparece com um >> asterisco que eu não sei o que é. Então... >> >> > Function.cph >> Error: object 'Function.cph' not found >> > Function.cph* >> + >> >> E a função não aparece. >> >> Pedro Brasil >> >> Em 25 de agosto de 2017 13:37, Marcus Nunes >> escreveu: >> >>> Use `methods` para encontrar os métodos da função desejada: >>> >>> > methods(Function) >>> [1] Function.areg.boot Function.transcan >>> see '?methods' for accessing help and source code >>> >>> Esta função tem dois métodos associados a ela: Function.areg.boot e >>> Function.transcan. Agora é só pedir pra ver o código fonte do método que te >>> interessa: >>> >>> > Function.areg.boot >>> function (object, type = c("list", "individual"), ytype = >>> c("transformed", >>> "inverse"), prefix = ".", suffix = "", pos = -1, ...) >>> { >>> type <- match.arg(type) >>> ytype <- match.arg(ytype) >>> if (missing(type) && !(missing(prefix) & missing(suffix) & >>> missing(pos))) >>> type <- "individual" >>> fit <- object$fit >>> k <- length(fit) >>> nam <- names(fit) >>> g <- vector("list", k) >>> xtype <- object$xtype >>> typey <- object$ytype >>> catl <- object$cat.levels >>> names(g) <- nam >>> for (i in 1:k) { >>> typ <- if (i == 1) >>> typey >>> else xtype[i - 1] >>> if (typ == "c") { >>> if (i == 1 && ytype == "inverse") >>> stop("currently does not handle ytype=\\"inverse\\" when >>> y is categorical") >>> h <- function(x, trantab) { >>> if (is.factor(x)) >>> x <- as.character(x) >>> trantab[x] >>> } >>> w <- fit[[i]]$y >>> names(w) <- catl[[nam[i]]] >>> formals(h) <- list(x = numeric(0), trantab = w) >>> } >>> else { >>> h <- function(x, trantab) { >>> s <- !is.na(x) >>> res <- rep(NA, length(x)) >>> res[s] <- approxExtrap(trantab, xout = x[s])$y >>> res >>> } >>> fiti <- fit[[i]] >>> formals(h) <- list(x = numeric(0), trantab = if (i == >>> 1 && ytype == "transformed") list(x = fiti[[2]], >>> y = fiti[[1]]) else fiti) >>> } >>> g[[i]] <- h >>> } >>> if (type == "list") >>> return(g) >>> fun.name <- paste(prefix, nam, suffix, sep = "") >>> for (i in 1:k) assign(fun.name[i], g[[i]], pos = pos) >>> invisible(fun.name) >>> } >>> >>> >>> >>> >>> >>> >>> >>> -- >>> Marcus Nunes >>> Professor Adjunto >>> Universidade Federal do Rio Grande do Norte >>> Centro de Ciências Exatas e da Terra >>> Departamento de Estatística >>> Laboratório de Estatística Aplicada >>> marcus.nu...@ccet.ufrn.br >>> http://marcusnunes.me/ >>> >>> >>> 2017-08-25 13:21 GMT-03:00 Pedro Emmanuel Alvarenga Americano do Brasil >>> via R-br : >>> Amigos de R, Gostaria de poder ver a sequencia de operações que uma função faz. Na maioria das funções, basta digitar o nome da função no console, por exemplo > trimws function (x, which = c("both", "left", "right")) { which <- match.arg(which) mysub <- function(re, x) sub(re, "", x, perl = TRUE) if (which == "left") return(mysub("^[ \t\r\n]+", x)) if (which == "right") return(mysub("[ \t\r\n]+$", x)) mysub("[ \t\r\n]+$", mysub("^[ \t\r\n]+", x)) } No entanto, algumas funções não seguem essa regra e eu não sei como fazer. Por exemplo library(Hmisc) > Function function (object, ...) UseMethod("Function") Alguma dica pra conseguir enxergar as operações dessa função? Abraço forte, Pedro Brasil ___ R-br mailing list R-br@listas.c3sl.ufpr.br https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça código mínimo reproduzível. >>> >>> >> >> ___ >> R-br mailing list >> R-br@listas.c3sl.ufpr.br >>
Re: [R-br] Como ver o que uma função faz
> Hmisc:::Function.cph Error in get(name, envir = asNamespace(pkg), inherits = FALSE) : object 'Function.cph' not found > Hmisc::Function.cph Error: 'Function.cph' não é um objeto exportado de 'namespace:Hmisc' > Hmisc:Function.cph Error: object 'Hmisc' not found > test1 <- list(time=c(4,3,1,1,2,2,3), + status=c(1,1,1,0,1,1,0), + x=c(0,2,1,1,1,0,0), + sex=c(0,0,0,0,1,1,1)) > fit1 <- cph(Surv(time, status) ~ x + sex, test1) > Function(fit1) function(x = NA,sex = NA) {-0.95815758+0.78116618*x+0.93375738*sex } > lp.fit1 <- Function(fit1) > lp.fit1(x = 3, sex = 1) # preditor linear de um sujeito de sexo = 1 e preditor x = 3. [1] 2.319098 > Pedro Brasil Em 25 de agosto de 2017 14:53, Tiago Fragosoescreveu: > Olá, > > Essa função não aparece nem pra mim nem pro Marcus quando usamos > methods(), capaz que ela não esteja em versões posteriores do Hmisc. > > O asterisco na saida do methods() indica uma função não exportada. Nesse > caso, Hmisc:::Function.cph deveria achar a função. Note os três ":". > > 2017-08-25 14:10 GMT-03:00 Pedro Emmanuel Alvarenga Americano do Brasil > via R-br : > >> Ei Marcus, >> >> No meu caso, eu gostaria de ver a Function.cph, mas ela aparece com um >> asterisco que eu não sei o que é. Então... >> >> > Function.cph >> Error: object 'Function.cph' not found >> > Function.cph* >> + >> >> E a função não aparece. >> >> Pedro Brasil >> >> Em 25 de agosto de 2017 13:37, Marcus Nunes >> escreveu: >> >>> Use `methods` para encontrar os métodos da função desejada: >>> >>> > methods(Function) >>> [1] Function.areg.boot Function.transcan >>> see '?methods' for accessing help and source code >>> >>> Esta função tem dois métodos associados a ela: Function.areg.boot e >>> Function.transcan. Agora é só pedir pra ver o código fonte do método que te >>> interessa: >>> >>> > Function.areg.boot >>> function (object, type = c("list", "individual"), ytype = >>> c("transformed", >>> "inverse"), prefix = ".", suffix = "", pos = -1, ...) >>> { >>> type <- match.arg(type) >>> ytype <- match.arg(ytype) >>> if (missing(type) && !(missing(prefix) & missing(suffix) & >>> missing(pos))) >>> type <- "individual" >>> fit <- object$fit >>> k <- length(fit) >>> nam <- names(fit) >>> g <- vector("list", k) >>> xtype <- object$xtype >>> typey <- object$ytype >>> catl <- object$cat.levels >>> names(g) <- nam >>> for (i in 1:k) { >>> typ <- if (i == 1) >>> typey >>> else xtype[i - 1] >>> if (typ == "c") { >>> if (i == 1 && ytype == "inverse") >>> stop("currently does not handle ytype=\\"inverse\\" when >>> y is categorical") >>> h <- function(x, trantab) { >>> if (is.factor(x)) >>> x <- as.character(x) >>> trantab[x] >>> } >>> w <- fit[[i]]$y >>> names(w) <- catl[[nam[i]]] >>> formals(h) <- list(x = numeric(0), trantab = w) >>> } >>> else { >>> h <- function(x, trantab) { >>> s <- !is.na(x) >>> res <- rep(NA, length(x)) >>> res[s] <- approxExtrap(trantab, xout = x[s])$y >>> res >>> } >>> fiti <- fit[[i]] >>> formals(h) <- list(x = numeric(0), trantab = if (i == >>> 1 && ytype == "transformed") list(x = fiti[[2]], >>> y = fiti[[1]]) else fiti) >>> } >>> g[[i]] <- h >>> } >>> if (type == "list") >>> return(g) >>> fun.name <- paste(prefix, nam, suffix, sep = "") >>> for (i in 1:k) assign(fun.name[i], g[[i]], pos = pos) >>> invisible(fun.name) >>> } >>> >>> >>> >>> >>> >>> >>> >>> -- >>> Marcus Nunes >>> Professor Adjunto >>> Universidade Federal do Rio Grande do Norte >>> Centro de Ciências Exatas e da Terra >>> Departamento de Estatística >>> Laboratório de Estatística Aplicada >>> marcus.nu...@ccet.ufrn.br >>> http://marcusnunes.me/ >>> >>> >>> 2017-08-25 13:21 GMT-03:00 Pedro Emmanuel Alvarenga Americano do Brasil >>> via R-br : >>> Amigos de R, Gostaria de poder ver a sequencia de operações que uma função faz. Na maioria das funções, basta digitar o nome da função no console, por exemplo > trimws function (x, which = c("both", "left", "right")) { which <- match.arg(which) mysub <- function(re, x) sub(re, "", x, perl = TRUE) if (which == "left") return(mysub("^[ \t\r\n]+", x)) if (which == "right") return(mysub("[ \t\r\n]+$", x)) mysub("[ \t\r\n]+$", mysub("^[ \t\r\n]+", x)) } No entanto, algumas funções não seguem essa regra e eu não sei como fazer. Por exemplo library(Hmisc) >
Re: [R-br] Como ver o que uma função faz
Olá, Essa função não aparece nem pra mim nem pro Marcus quando usamos methods(), capaz que ela não esteja em versões posteriores do Hmisc. O asterisco na saida do methods() indica uma função não exportada. Nesse caso, Hmisc:::Function.cph deveria achar a função. Note os três ":". 2017-08-25 14:10 GMT-03:00 Pedro Emmanuel Alvarenga Americano do Brasil via R-br: > Ei Marcus, > > No meu caso, eu gostaria de ver a Function.cph, mas ela aparece com um > asterisco que eu não sei o que é. Então... > > > Function.cph > Error: object 'Function.cph' not found > > Function.cph* > + > > E a função não aparece. > > Pedro Brasil > > Em 25 de agosto de 2017 13:37, Marcus Nunes > escreveu: > >> Use `methods` para encontrar os métodos da função desejada: >> >> > methods(Function) >> [1] Function.areg.boot Function.transcan >> see '?methods' for accessing help and source code >> >> Esta função tem dois métodos associados a ela: Function.areg.boot e >> Function.transcan. Agora é só pedir pra ver o código fonte do método que te >> interessa: >> >> > Function.areg.boot >> function (object, type = c("list", "individual"), ytype = >> c("transformed", >> "inverse"), prefix = ".", suffix = "", pos = -1, ...) >> { >> type <- match.arg(type) >> ytype <- match.arg(ytype) >> if (missing(type) && !(missing(prefix) & missing(suffix) & >> missing(pos))) >> type <- "individual" >> fit <- object$fit >> k <- length(fit) >> nam <- names(fit) >> g <- vector("list", k) >> xtype <- object$xtype >> typey <- object$ytype >> catl <- object$cat.levels >> names(g) <- nam >> for (i in 1:k) { >> typ <- if (i == 1) >> typey >> else xtype[i - 1] >> if (typ == "c") { >> if (i == 1 && ytype == "inverse") >> stop("currently does not handle ytype=\\"inverse\\" when >> y is categorical") >> h <- function(x, trantab) { >> if (is.factor(x)) >> x <- as.character(x) >> trantab[x] >> } >> w <- fit[[i]]$y >> names(w) <- catl[[nam[i]]] >> formals(h) <- list(x = numeric(0), trantab = w) >> } >> else { >> h <- function(x, trantab) { >> s <- !is.na(x) >> res <- rep(NA, length(x)) >> res[s] <- approxExtrap(trantab, xout = x[s])$y >> res >> } >> fiti <- fit[[i]] >> formals(h) <- list(x = numeric(0), trantab = if (i == >> 1 && ytype == "transformed") list(x = fiti[[2]], >> y = fiti[[1]]) else fiti) >> } >> g[[i]] <- h >> } >> if (type == "list") >> return(g) >> fun.name <- paste(prefix, nam, suffix, sep = "") >> for (i in 1:k) assign(fun.name[i], g[[i]], pos = pos) >> invisible(fun.name) >> } >> >> >> >> >> >> >> >> -- >> Marcus Nunes >> Professor Adjunto >> Universidade Federal do Rio Grande do Norte >> Centro de Ciências Exatas e da Terra >> Departamento de Estatística >> Laboratório de Estatística Aplicada >> marcus.nu...@ccet.ufrn.br >> http://marcusnunes.me/ >> >> >> 2017-08-25 13:21 GMT-03:00 Pedro Emmanuel Alvarenga Americano do Brasil >> via R-br : >> >>> Amigos de R, >>> >>> Gostaria de poder ver a sequencia de operações que uma função faz. Na >>> maioria das funções, basta digitar o nome da função no console, por exemplo >>> >>> > trimws >>> function (x, which = c("both", "left", "right")) >>> { >>> which <- match.arg(which) >>> mysub <- function(re, x) sub(re, "", x, perl = TRUE) >>> if (which == "left") >>> return(mysub("^[ \t\r\n]+", x)) >>> if (which == "right") >>> return(mysub("[ \t\r\n]+$", x)) >>> mysub("[ \t\r\n]+$", mysub("^[ \t\r\n]+", x)) >>> } >>> >>> >>> >>> No entanto, algumas funções não seguem essa regra e eu não sei como >>> fazer. Por exemplo >>> >>> library(Hmisc) >>> > Function >>> function (object, ...) >>> UseMethod("Function") >>> >>> >>> Alguma dica pra conseguir enxergar as operações dessa função? >>> >>> Abraço forte, >>> >>> Pedro Brasil >>> >>> ___ >>> R-br mailing list >>> R-br@listas.c3sl.ufpr.br >>> https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br >>> Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça >>> código mínimo reproduzível. >>> >> >> > > ___ > R-br mailing list > R-br@listas.c3sl.ufpr.br > https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br > Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça > código mínimo reproduzível. > ___ R-br mailing list R-br@listas.c3sl.ufpr.br https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e
Re: [R-br] Como ver o que uma função faz
Ei Marcus, No meu caso, eu gostaria de ver a Function.cph, mas ela aparece com um asterisco que eu não sei o que é. Então... > Function.cph Error: object 'Function.cph' not found > Function.cph* + E a função não aparece. Pedro Brasil Em 25 de agosto de 2017 13:37, Marcus Nunesescreveu: > Use `methods` para encontrar os métodos da função desejada: > > > methods(Function) > [1] Function.areg.boot Function.transcan > see '?methods' for accessing help and source code > > Esta função tem dois métodos associados a ela: Function.areg.boot e > Function.transcan. Agora é só pedir pra ver o código fonte do método que te > interessa: > > > Function.areg.boot > function (object, type = c("list", "individual"), ytype = c("transformed", > "inverse"), prefix = ".", suffix = "", pos = -1, ...) > { > type <- match.arg(type) > ytype <- match.arg(ytype) > if (missing(type) && !(missing(prefix) & missing(suffix) & > missing(pos))) > type <- "individual" > fit <- object$fit > k <- length(fit) > nam <- names(fit) > g <- vector("list", k) > xtype <- object$xtype > typey <- object$ytype > catl <- object$cat.levels > names(g) <- nam > for (i in 1:k) { > typ <- if (i == 1) > typey > else xtype[i - 1] > if (typ == "c") { > if (i == 1 && ytype == "inverse") > stop("currently does not handle ytype=\\"inverse\\" when y > is categorical") > h <- function(x, trantab) { > if (is.factor(x)) > x <- as.character(x) > trantab[x] > } > w <- fit[[i]]$y > names(w) <- catl[[nam[i]]] > formals(h) <- list(x = numeric(0), trantab = w) > } > else { > h <- function(x, trantab) { > s <- !is.na(x) > res <- rep(NA, length(x)) > res[s] <- approxExtrap(trantab, xout = x[s])$y > res > } > fiti <- fit[[i]] > formals(h) <- list(x = numeric(0), trantab = if (i == > 1 && ytype == "transformed") list(x = fiti[[2]], > y = fiti[[1]]) else fiti) > } > g[[i]] <- h > } > if (type == "list") > return(g) > fun.name <- paste(prefix, nam, suffix, sep = "") > for (i in 1:k) assign(fun.name[i], g[[i]], pos = pos) > invisible(fun.name) > } > > > > > > > > -- > Marcus Nunes > Professor Adjunto > Universidade Federal do Rio Grande do Norte > Centro de Ciências Exatas e da Terra > Departamento de Estatística > Laboratório de Estatística Aplicada > marcus.nu...@ccet.ufrn.br > http://marcusnunes.me/ > > > 2017-08-25 13:21 GMT-03:00 Pedro Emmanuel Alvarenga Americano do Brasil > via R-br : > >> Amigos de R, >> >> Gostaria de poder ver a sequencia de operações que uma função faz. Na >> maioria das funções, basta digitar o nome da função no console, por exemplo >> >> > trimws >> function (x, which = c("both", "left", "right")) >> { >> which <- match.arg(which) >> mysub <- function(re, x) sub(re, "", x, perl = TRUE) >> if (which == "left") >> return(mysub("^[ \t\r\n]+", x)) >> if (which == "right") >> return(mysub("[ \t\r\n]+$", x)) >> mysub("[ \t\r\n]+$", mysub("^[ \t\r\n]+", x)) >> } >> >> >> >> No entanto, algumas funções não seguem essa regra e eu não sei como >> fazer. Por exemplo >> >> library(Hmisc) >> > Function >> function (object, ...) >> UseMethod("Function") >> >> >> Alguma dica pra conseguir enxergar as operações dessa função? >> >> Abraço forte, >> >> Pedro Brasil >> >> ___ >> R-br mailing list >> R-br@listas.c3sl.ufpr.br >> https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br >> Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça >> código mínimo reproduzível. >> > > ___ R-br mailing list R-br@listas.c3sl.ufpr.br https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forne�a c�digo m�nimo reproduz�vel.
Re: [R-br] Como ver o que uma função faz
Use `methods` para encontrar os métodos da função desejada: > methods(Function) [1] Function.areg.boot Function.transcan see '?methods' for accessing help and source code Esta função tem dois métodos associados a ela: Function.areg.boot e Function.transcan. Agora é só pedir pra ver o código fonte do método que te interessa: > Function.areg.boot function (object, type = c("list", "individual"), ytype = c("transformed", "inverse"), prefix = ".", suffix = "", pos = -1, ...) { type <- match.arg(type) ytype <- match.arg(ytype) if (missing(type) && !(missing(prefix) & missing(suffix) & missing(pos))) type <- "individual" fit <- object$fit k <- length(fit) nam <- names(fit) g <- vector("list", k) xtype <- object$xtype typey <- object$ytype catl <- object$cat.levels names(g) <- nam for (i in 1:k) { typ <- if (i == 1) typey else xtype[i - 1] if (typ == "c") { if (i == 1 && ytype == "inverse") stop("currently does not handle ytype=\\"inverse\\" when y is categorical") h <- function(x, trantab) { if (is.factor(x)) x <- as.character(x) trantab[x] } w <- fit[[i]]$y names(w) <- catl[[nam[i]]] formals(h) <- list(x = numeric(0), trantab = w) } else { h <- function(x, trantab) { s <- !is.na(x) res <- rep(NA, length(x)) res[s] <- approxExtrap(trantab, xout = x[s])$y res } fiti <- fit[[i]] formals(h) <- list(x = numeric(0), trantab = if (i == 1 && ytype == "transformed") list(x = fiti[[2]], y = fiti[[1]]) else fiti) } g[[i]] <- h } if (type == "list") return(g) fun.name <- paste(prefix, nam, suffix, sep = "") for (i in 1:k) assign(fun.name[i], g[[i]], pos = pos) invisible(fun.name) } -- Marcus Nunes Professor Adjunto Universidade Federal do Rio Grande do Norte Centro de Ciências Exatas e da Terra Departamento de Estatística Laboratório de Estatística Aplicada marcus.nu...@ccet.ufrn.br http://marcusnunes.me/ 2017-08-25 13:21 GMT-03:00 Pedro Emmanuel Alvarenga Americano do Brasil via R-br: > Amigos de R, > > Gostaria de poder ver a sequencia de operações que uma função faz. Na > maioria das funções, basta digitar o nome da função no console, por exemplo > > > trimws > function (x, which = c("both", "left", "right")) > { > which <- match.arg(which) > mysub <- function(re, x) sub(re, "", x, perl = TRUE) > if (which == "left") > return(mysub("^[ \t\r\n]+", x)) > if (which == "right") > return(mysub("[ \t\r\n]+$", x)) > mysub("[ \t\r\n]+$", mysub("^[ \t\r\n]+", x)) > } > > > > No entanto, algumas funções não seguem essa regra e eu não sei como fazer. > Por exemplo > > library(Hmisc) > > Function > function (object, ...) > UseMethod("Function") > > > Alguma dica pra conseguir enxergar as operações dessa função? > > Abraço forte, > > Pedro Brasil > > ___ > R-br mailing list > R-br@listas.c3sl.ufpr.br > https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br > Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça > código mínimo reproduzível. > ___ R-br mailing list R-br@listas.c3sl.ufpr.br https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forne�a c�digo m�nimo reproduz�vel.