Fixed bug with writing R data files