gpt4 book ai didi

r - 使用 Safely from Purrr 时调试函数?

转载 作者:行者123 更新时间:2023-12-04 00:57:32 28 4
gpt4 key购买 nike

我有一个已保存为 Rds 对象的函数,我想知道是否有可能读取该函数后对其debug() 或看到函数内的代码了吗?

例子

library(purrr)

some_function <- function(x){


avg <- mean(x)
std <- sd(x)

return(c(avg, std))

}

safe_function <- safely(some_function)

saveRDS(safe_function, 'safe_function.rds')
rm(safe_function)

# How can I debug the function or make changes to it after I've loaded it?

safe_function <- readRDS('safe_function.rds')

最佳答案

这是一种方法:

  1. 在控制台中执行 debug(safe_function),然后调用您的函数,比如 safe_function(c(1, 2))
  2. 此时,您将处于 Debug模式: enter image description here
  3. 在您的控制台中,执行 debugonce(.f) 然后点击“下一步”或“继续”(或者,键入 nc在控制台中)
  4. 您现在将位于 some_function 的主体内,并且能够看到代码: enter image description here

关于r - 使用 Safely from Purrr 时调试函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61278053/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com