How to handle binary strings in R?

前端 未结 2 1897
离开以前
离开以前 2020-12-29 11:56

R is not able to cope with null-strings (\\0) in characters, does anyone know how to handle this? More concrete, I want to store complex R objects within a database using an

2条回答
  •  天命终不由人
    2020-12-29 12:41

    You need

    stringModel <- as.character(serialModel)
    

    for a character representation of the raw bit codes. rawToChar will try to convert the raw bit codes, which is not what you want in this case.

    The resulting stringModel can be converted later on back to the original model by :

    newSerialModel <- as.raw(as.hexmode(stringModel))
    newModel <- unserialize(newSerialModel)
    all.equal(model,newModel)
    [1] TRUE
    

    Regarding the writing of binary types to databases through RODBC : as for today, the vignette of RODBC reads (p.11) :

    Binary types can currently only be read as such, and they are returned as column of class "ODBC binary" which is a list of raw vectors.

提交回复
热议问题