How to wait for a keypress in R?

As someone already wrote in a comment, you don’t have to use the cat before readline(). Simply write: readline(prompt=”Press [enter] to continue”) If you don’t want to assign it to a variable and don’t want a return printed in the console, wrap the readline() in an invisible(): invisible(readline(prompt=”Press [enter] to continue”))

Using R to list all files with a specified extension

files <- list.files(pattern = “\\.dbf$”) $ at the end means that this is end of string. “dbf$” will work too, but adding \\. (. is special character in regular expressions so you need to escape it) ensure that you match only files with extension .dbf (in case you have e.g. .adbf files).

Use tryCatch skip to next value of loop upon error?

The key to using tryCatch is realising that it returns an object. If there was an error inside the tryCatch then this object will inherit from class error. You can test for class inheritance with the function inherit. x <- tryCatch(stop(“Error”), error = function(e) e) class(x) “simpleError” “error” “condition” Edit: What is the meaning of … Read more

Add new row to dataframe, at specific row-index, not appended?

Here’s a solution that avoids the (often slow) rbind call: existingDF <- as.data.frame(matrix(seq(20),nrow=5,ncol=4)) r <- 3 newrow <- seq(4) insertRow <- function(existingDF, newrow, r) { existingDF[seq(r+1,nrow(existingDF)+1),] <- existingDF[seq(r,nrow(existingDF)),] existingDF[r,] <- newrow existingDF } > insertRow(existingDF, newrow, r) V1 V2 V3 V4 1 1 6 11 16 2 2 7 12 17 3 1 2 3 … Read more