Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Converting back to list from raw in R

Converting back to list from raw in R

Expert Contributor

I have my data in a list which I can access like:

  1. print(max(gaDataEcommerce4$date))

Now, I save it in a text file in HDFS and what I read back from this file is a raw object.

I then convert it to a list but on trying to access $date get null.

<code>getLastDataImportDate =function(){
  hdfs.init()
  f = hdfs.file("/user/rstudio/gaDataEcommerce4","r")
  m = hdfs.read(f)
  print(typeof(m))//raw
  m1 <- m
  mnull <- m == as.raw(0)//What is happening here?
  m1[mnull]<- as.raw(20)//and here?
  c <- rawToChar(m1)
  print(c)
  print(typeof(c))//character
  df = as.list(c)
  print(df)
  print(df$date)//NULL}
  1. I could not directly use rawToChar function because I have nulls in the data.

So found this for the fix but I would really like to know what exactly is happening at these 2 lines.

<code>  mnull <- m == as.raw(0)//What is happening here?
  m1[mnull]<- as.raw(20)//and here?

Also, I tried converting it to a list but

df$date gives NULL. Why exactly is that? I need to get max(df$date), how else would I get it?