Created
May 23, 2014 15:28
-
-
Save JoFrhwld/26c42b35a5b4fc5a5bb8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' SQL Load | |
#' | |
#' This is function meant to be used along with ldply to read data in using sqldf. | |
#' | |
#' @param x the path to a file to be read | |
#' @param selection the columns to return. Defaults to \code{"*"} | |
#' @param condition conditions defining which data rows to load in SQL | |
#' @param file.format an argument to be passed to \code{sqldf}. | |
#' Defaults to assume a tab-delimited file with a header row. | |
#' See \code{?sqldf} for more info | |
#' | |
#' @return A data frame | |
#' | |
#' @export | |
#' @import sqldf | |
sql_load <- function(x, selection = "*", condition, file.format = list(header = TRUE, sep = "\t")){ | |
fi <- file(x) | |
df <- sqldf(paste("select", selection, "from fi", condition, sep = " "), | |
file.format = file.format) | |
close(fi) | |
if(nrow(df)>0){ | |
df$File <- basename(x) | |
} | |
return(df) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment