Learn R Programming

arules (version 1.7-9)

write: Write Transactions or Associations to a File

Description

Provides the generic function write() and the methods to write transactions or associations to a file.

Usage

write(x, file = "", ...)

# S4 method for transactions write( x, file = "", format = c("basket", "single"), sep = " ", quote = TRUE, ... )

# S4 method for associations write(x, file = "", sep = " ", quote = TRUE, ...)

Arguments

x

the transactions or associations (rules, itemsets, etc.) object.

file

either a character string naming a file or a connection open for writing. '""' indicates output to the console.

...

further arguments passed on to write.table(). Use fileEncoding to set the encoding used for writing the file.

format

format to write transactions.

sep

the field separator string. Values within each row of x are separated by this string. Use quote = TRUE and sep = "," for saving data as in csv format.

quote

a logical value. Quote fields?

Author

Michael Hahsler

Details

For associations (rules and itemsets) write() first uses coercion to data.frame to obtain a printable form of x and then uses utils::write.table() to write the data to disk. This is just a method to export the rules in human-readable form. These exported associations cannot be read back in as rules. To save and load associations in compact form, use save() and load() from the base package. Alternatively, association can be written to disk in PMML (Predictive Model Markup Language) via write.PMML(). This requires package pmml.

Transactions can be saved in basket (one line per transaction) or in single (one line per item) format.

See Also

Other import/export: DATAFRAME(), LIST(), pmml, read

Examples

Run this code
data("Epub")

## write the formated transactions to screen (basket format)
write(head(Epub))

## write the formated transactions to screen (single format)
write(head(Epub), format = "single")

## write the formated result to file in CSV format
write(Epub, file = "data.csv", format = "single", sep = ",")

## write rules in CSV format
rules <- apriori(Epub, parameter = list(support = 0.0005, conf = 0.8))
write(rules, file = "data.csv", sep = ",")

unlink("data.csv") # tidy up

Run the code above in your browser using DataLab