Examples on saving

Writing/Reading text files

  • Writing text to files
from rlike import *
f = writeLines(text = "Hi there. Some\ntext", con = "fname.txt")
f = writeLines(text = ["I", "want", "to", "break free."], con = "fname.txt")
x = readLines("fname.txt")
x
['I', 'want', 'to', 'break free.']

Saving objects

  • Saving python objects similarly as readRDS and writeRDS
f = savePickle({"a": 0, "b": ["x", "y"]}, file = "mydata.pickle")
readPickle("mydata.pickle")
{'a': 0, 'b': ['x', 'y']}

Zipped operations

  • Basic operations on zip files
folder = tempdir()
f1 = writeLines(text = 'Hello world. Some more text.', con = file_path(folder, 'fname1.txt'))
f2 = writeLines(text = 'Hello world. Some more text.', con = file_path(folder, 'fname2.txt'))
zip_archive(folder, file = 'xyz.zip')
'xyz.zip'
file_exists("xyz.zip")
True
paths = unzip('xyz.zip', path = tempdir())
paths
['/tmp/tmpud4x_tff/fname1.txt', '/tmp/tmpud4x_tff/fname2.txt']