{"id":156,"date":"2017-12-05T17:17:56","date_gmt":"2017-12-05T17:17:56","guid":{"rendered":"http:\/\/eipsoftware.com\/musings\/?p=156"},"modified":"2018-02-01T17:18:13","modified_gmt":"2018-02-01T17:18:13","slug":"file-handler-for-rds-formatted-files","status":"publish","type":"post","link":"https:\/\/eipsoftware.com\/musings\/file-handler-for-rds-formatted-files\/","title":{"rendered":"File Handler for RDS Formatted Files"},"content":{"rendered":"<h4>File Handler for RDS Formatted Files<\/h4>\n<p>Using a list, load RDS formatted files into standard data frame. Allows for grouping multiple files into one data frame for processing.<\/p>\n<p>See code below<!--more--><\/p>\n<pre class=\"lang:r decode:true \">#sample file handler\r\n# ----------------------------------------------------------\r\n#' class for handling the sample files\r\n#' @param file directory location\r\n#' @param file_extenstion pattern to identify what files to load\r\n#'\r\nfileHandlerSample &lt;- setClass(\"fileHandlerSample\", slots = list(directory = \"character\"\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t,file_extenstion = \"character\"\r\n\t\t\t\t\t\t\t\t))\r\nloadRDSFiles &lt;- function(userobject){}\r\n\r\n# ----------------------------------------------------------\r\n#' method loadRDSFiles used to load RDS files from\r\n#' specified directory\r\n#' @return list vector with samples from each file\r\nsetMethod(\"loadRDSFiles\",\"fileHandlerSample\",function(userobject)\r\n{\r\n\tlistRDSFiles &lt;- list.files(path = userobject@directory\r\n\t\t\t\t\t\t\t\t, pattern = userobject@file_extenstion\r\n\t\t\t\t\t\t\t\t, full.names = TRUE)\r\n\r\n\t#check to see found RDS files\r\n\ttry(if(length(listRDSFiles) &lt; 1) stop(\"No RDS files found\"))\r\n\r\n\tfiles &lt;- list()\r\n\t#loop through list of files and load each one\r\n\tfor(current_file in listRDSFiles)\r\n\t{\r\n\t\t#load the file, convert to corpus on the fly\r\n\t\tmessage(c(\".... Loading file: \", current_file))\r\n\t\tstore_current_file &lt;- readRDS(current_file)\r\n\t\tfiles &lt;- c(files, store_current_file)\r\n\t\trm(store_current_file)\r\n\t}\r\n\treturn(files)\r\n})<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>File Handler for RDS Formatted Files Using a list, load RDS formatted files into standard data frame. Allows for grouping multiple files into one data frame for processing. See code below<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[4,5],"tags":[30,35,36,37],"series":[],"class_list":["post-156","post","type-post","status-publish","format-standard","hentry","category-code","category-r","tag-code","tag-r","tag-class","tag-file-handler"],"_links":{"self":[{"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/posts\/156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/comments?post=156"}],"version-history":[{"count":1,"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/posts\/156\/revisions"}],"predecessor-version":[{"id":157,"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/posts\/156\/revisions\/157"}],"wp:attachment":[{"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/media?parent=156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/categories?post=156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/tags?post=156"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/eipsoftware.com\/musings\/wp-json\/wp\/v2\/series?post=156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}