Created
December 7, 2018 06:47
-
-
Save sudevschiz/87306615edffd4716aa36b2a22614d94 to your computer and use it in GitHub Desktop.
How to read directly from .sql files to R. #https://stackoverflow.com/a/44886192/3498721
This file contains hidden or 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
#Function found in the stackoverflow question. | |
getSQL <- function(filepath){ | |
con = file(filepath, "r") | |
sql.string <- "" | |
while (TRUE){ | |
line <- readLines(con, n = 1) | |
if ( length(line) == 0 ){ | |
break | |
} | |
line <- gsub("\\t", " ", line) | |
if(grepl("--",line) == TRUE){ | |
line <- paste(sub("--","/*",line),"*/") | |
} | |
sql.string <- paste(sql.string, line) | |
} | |
close(con) | |
return(sql.string) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment