Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Use R's native data editor to edit a CSV
#' Use the data editor for a CSV file
#' This function loads a CSV file, lets the user edit it in the native data
#' editor, then re-saves it, prompting the user for a new file name if desired.
fix.csv <- function(file,, sep=",", comment.char="") {
tmpframe <- read.csv(file, sep=sep,quote="", colClasses="character",
stringsAsFactors=FALSE, comment.char="",
blank.lines.skip=FALSE, na.strings="")
tmpframe <- edit(tmpframe)
if(is.character( { <-
} else if( <- TRUE) { <- readline(prompt="Enter file name to save (Hit enter to use original):")
} else { <- file
if("") <- file
write.table(tmpframe,, append=FALSE, quote=FALSE, sep=sep,

This comment has been minimized.

Copy link

@tylerhoecker tylerhoecker commented Nov 16, 2017

This is cool! I occasionally have to make small, permanent edits to a csv that are easier done in an editor than in code. Having to open Excel is annoying, and this is a great solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment