try-catch

how to properly close connection so I won't get “Error in file(con, ”r“) : all connections are in use” when using “readlines” and “tryCatch”

孤者浪人 提交于 2020-11-29 19:58:40
问题 I have a list of URLs (more than 4000) from a specific domain (pixilink.com) and what I want to do is to figure out if the provided domain is a picture or a video. To do this, I used the solutions provided here: How to write trycatch in R and Check whether a website provides photo or video based on a pattern in its URL and wrote the code shown below: #Function to get the value of initial_mode from the URL urlmode <- function(x){ mycontent <- readLines(x) mypos <- grep("initial_mode = ",

how to properly close connection so I won't get “Error in file(con, ”r“) : all connections are in use” when using “readlines” and “tryCatch”

你说的曾经没有我的故事 提交于 2020-11-29 19:53:52
问题 I have a list of URLs (more than 4000) from a specific domain (pixilink.com) and what I want to do is to figure out if the provided domain is a picture or a video. To do this, I used the solutions provided here: How to write trycatch in R and Check whether a website provides photo or video based on a pattern in its URL and wrote the code shown below: #Function to get the value of initial_mode from the URL urlmode <- function(x){ mycontent <- readLines(x) mypos <- grep("initial_mode = ",

Is there a way to use tryCatch (or similar) in R as a loop, or to manipulate the expr in the warning argument?

这一生的挚爱 提交于 2020-11-29 09:52:28
问题 I have a regression model ( lm or glm or lmer ...) and I do fitmodel <- lm(inputs) where inputs changes inside a loop (the formula and the data). Then, if the model function does not produce any warning I want to keep fitmodel , but if I get a warning I want to update the model and I want the warning not printed, so I do fitmodel <- lm(inputs) inside tryCatch . So, if it produces a warning, inside warning = function(w){f(fitmodel)} , f(fitmodel) would be something like fitmodel <- update