It is also possible to use the new (as of v0.6.0) function export_list() to write a list of data frames to multiple files using either a vector of file names or a file pattern: export_list(list(mtcars = mtcars, iris = iris), "%s.tsv") Rdata fileĮxport(list(mtcars = mtcars, iris = iris), "multi.rdata")Įxport(c("mtcars", "iris"), "multi.rdata") export() natively supports output of multiple objects to these types of files: # export to sheets of an Excel workbookĮxport(list(mtcars = mtcars, iris = iris), "multi.xlsx") # export to an. Some file formats (e.g., Excel workbooks, Rdata files) can support multiple data objects in a single file. For example, the following code uses export() to save the results of a simple data transformation: library("magrittr")Īggregate(. It is also easy to use export() as part of an R pipeline (from magrittr or dplyr). That said, rio currently supports the following formats: library("rio") The export capabilities of rio are somewhat more limited than the import capabilities, given the availability of different functions in various R packages and because import functions are often written to make use of data from other applications and it never seems to be a development priority to have functions to export to the formats used by other applications. For example, we can read in a CSV file that does not have a file extension by specifying csv: head(import("mtcars_noext", format = "csv")) # mpg cyl disp hp drat wt qsec vs am gear carb If for some reason a file does not have an extension, or has a file extension that does not match its actual type, you can manually specify a file format to override the format inference step. library("rio")Īll.equal(x, y, check.attributes = FALSE) # TRUE all.equal(x, z, check.attributes = FALSE) # TRUE This works for any for the formats listed above. import() infers the file format from the file’s extension and calls the appropriate data import function for you, returning a simple ame. Rio allows you to import files in almost any format using one, typically single-argument, function. Unrecognized formats will yield a simple “Unrecognized file format” error. The full list of supported formats is below: NameĪdditionally, any format that is not supported by rio but that has a known R implementation will produce an informative error message pointing to a package and import or export function. To ensure rio is fully functional, install these packages the first time you use rio via: install_formats() To keep the package slim, all non-essential formats are supported via “Suggests” packages, which are not installed (or loaded) by default. Rio supports a variety of different file formats for import and export. The convert function therefore combines import and export to easily convert between file formats (thus providing a FOSS replacement for programs like Stat/Transfer or Sledgehammer). Transferring data files between various proprietary formats is always a pain and often expensive. By taking away the need to manually match a file type (which a beginner may not recognize) to a particular import or export function, rio allows almost all common data formats to be read with the same function.īy making import and export easy, it’s an obvious next step to also use R as a simple data conversion utility. This is the same logic used by Windows OS, for example, in determining what application is associated with a given file type. Specifically, rio uses the file extension of a file name to determine what kind of file it is. The core advantage of rio is that it makes assumptions that the user is probably willing to make. rio aims to unify data I/O (importing and exporting) into two simple functions: import() and export() so that beginners (and experienced R users) never have to think twice (or even once) about the best way to read and write R data. Faster, simpler, packages with fewer dependencies have been created for many of the file types described in that document. And, despite all of that text, most of the packages described are (to varying degrees) out-of-date. Indeed, R supplies an entire manual describing the process of data import/export. This process is, probably unnecessarily, extremely complex for beginning R users. The idea behind rio is to simplify the process of importing data into R and exporting data from R.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |