Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Rstudio has crashed while working and the unsaved files were not able to be loaded into the session. But the files are available in the JSON format. An example,

{
    "contents" : "library(hgu133a.db)
x <- hgu133aENSEMBL
x
length(x)
count.mappedkeys(x)
x[1:3]
links(x[1:3])

## Keep only the mapped keys
keys(x) <- mappedkeys(x)
length(x)
count.mappedkeys(x)
x # now it is a submap

## The above subsetting can also be achieved with
x <- hgu133aENSEMBL[mappedkeys(hgu133aENSEMBL)]

",
    "created" : 1463131195093.000,
    "dirty" : true,
    "encoding" : "",
    "folds" : "",
    "hash" : "1482602869",
    "id" : "737C178C",
    "lastKnownWriteTime" : 0,
    "path" : null,
    "project_path" : null,
    "properties" : {
        "tempName" : "Untitled3"
    },
    "source_on_save" : false,
    "type" : "r_source"
}

The JSON format files can be read using the jsonlite::fromJSON and the required information was stored in contents variable. When tried to read the commands using the readLines() or scan() the commands were being executed instead of converting them into a simple file. How to convert this into a r file ?

output(?):command in a r script/text file.

library(hgu133a.db)
x <- hgu133aENSEMBL
x
length(x)
count.mappedkeys(x)
x[1:3]
links(x[1:3])

## Keep only the mapped keys
keys(x) <- mappedkeys(x)
length(x)
count.mappedkeys(x)
x 
# now it is a submap

## The above subsetting can also be achieved with
x <- hgu133aENSEMBL[mappedkeys(hgu133aENSEMBL)]
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
143 views
Welcome To Ask or Share your Answers For Others

1 Answer

If anyone looking for answer to this question, the command suggested by @Kevin worked.

writeLines(json$contents, con = "/path/to/file.R")

Output:

library(hgu133a.db)
x <- hgu133aENSEMBL
x
length(x)
count.mappedkeys(x)
x[1:3]
links(x[1:3])

## Keep only the mapped keys
keys(x) <- mappedkeys(x)
length(x)
count.mappedkeys(x)
x # now it is a submap

## The above subsetting can also be achieved with
x <- hgu133aENSEMBL[mappedkeys(hgu133aENSEMBL)]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...