r – How to append new rows to .RDS file in Rstudio using write() function

I execute the below line in RStudio to append a text to myfile.rds, which contains only one column named X

write("mytext", file = "myfile.rds", append = TRUE)

It executes without throwing any error or warning as shown below

> write("mytext", file = "myfile.rds", append = TRUE)
> 

However, when I import the myfile.rds dataset to view it the text is not added and I get the following warnings.

> myfile <- read.table("D:/.../.../myfile.rds", header=TRUE, quote="\"")
There were 12 warnings (use warnings() to see them)
>   View(myfile)

On executing warnings(), the below warnings are displayed:

Warning messages:
1: In read.table(path, encoding = encoding, header = header,  ... :
  line 2 appears to contain embedded nulls
2: In read.table(path, encoding = encoding, header = header,  ... :
  line 3 appears to contain embedded nulls
3: In read.table(path, encoding = encoding, header = header,  ... :
  line 4 appears to contain embedded nulls
4: In read.table(path, encoding = encoding, header = header,  ... :
  line 5 appears to contain embedded nulls
5: In scan(file = file, what = what, sep = sep, quote = quote,  ... :
  embedded nul(s) found in input
6: 'default.stringsAsFactors' is deprecated.
Use '`stringsAsFactors = FALSE`' instead.
See help("Deprecated")
7: In read.table("D:/.../.../myfile.rds",  ... :
  line 2 appears to contain embedded nulls
8: In read.table("D:/.../.../myfile.rds",  ... :
  line 3 appears to contain embedded nulls
9: In read.table("D:/.../.../myfile.rds",  ... :
  line 4 appears to contain embedded nulls
10: In read.table("D:/.../.../myfile.rds",  ... :
  line 5 appears to contain embedded nulls
11: In scan(file = file, what = what, sep = sep, quote = quote,  ... :
  EOF within quoted string
12: In scan(file = file, what = what, sep = sep, quote = quote,  ... :
  embedded nul(s) found in input
> 

I tried to append the same text to a new .rds file and the text is successfully appended. Any suggestion on how I can fix this? Unfortunately I am not in a position
to share the contents of the myfile.rds file due to privacy issues.

Read more here: Source link