Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 7286247ba7901271e14bcdb1093ac759e51f36c5 authored by Alexey Sergushichev on 06 September 2022, 18:44:17 UTC, committed by Alexey Sergushichev on 06 September 2022, 18:44:17 UTC
update js
1 parent b9a3c55
  • Files
  • Changes
  • 168e88d
  • /
  • R
  • /
  • reproduceInR.R
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:7286247ba7901271e14bcdb1093ac759e51f36c5
directory badge
swh:1:dir:5e6d569d111f61e263d07affc073d497fce06720
content badge
swh:1:cnt:a101ef71d7298b6485396c6c6870543a85b06e49

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
reproduceInR.R
rootFn <- c('loadGEO', 'loadPreloaded', 'createES')
complexArgumentLimitBytes <- 400

#' Reproduce session in R code
#'
#' @param sessionName String, OCPU session name
#' @param leaf Boolean, is it leaf (default = F)
#' @param step Integer, step of recursion (default = 0)
#' @param savedEnv Environment, where to store complex arguments (default = new.env())
#'
#' @return JSON with R code
#' @importFrom utils object.size
#' @examples
#' \dontrun{
#'   setwd(tempdir())
#'   reproduceInR('x039f1672026678');
#' }
reproduceInR <- function (sessionName, leaf = T, step = 0, savedEnv = new.env()) {
    ocpuRoot <- strsplit(getwd(), 'ocpu-temp')[[1]][1]
    sessionPath <- paste(ocpuRoot, 'ocpu-store', sessionName, sep=.Platform$file.sep)
    RDataPath <- paste(sessionPath, '.RData', sep=.Platform$file.sep)
    REvalPath <- paste(sessionPath, '.REval', sep=.Platform$file.sep)

    rds <- readRDS(REvalPath)
    env <- new.env()
    loadedVariables <- load(RDataPath, envir = env)
    parsed <- parse(text=rds[[1]]$src)
    fn <- parsed[[1]][[1]]
    complexArguments <- "";
    for(i in 2:length(parsed[[1]])) {
        argumentName <- toString(parsed[[1]][[i]])
        if (argumentName %in% loadedVariables) {
            argumentValue <- env[[argumentName]]
            if (object.size(argumentValue) > complexArgumentLimitBytes) {
                rawArgument <- paste(argumentName, '_', step, sep='')
                savedEnv[[rawArgument]] <- argumentValue
            } else {
                rawArgument <- paste(deparse(argumentValue), collapse = '\n')
            }

            complexArgument <- paste(argumentName, ' <- ', rawArgument)
            complexArguments <- paste(complexArguments, complexArgument, sep='\n')
        }
    }

    if ('es' %in% names(parsed[[1]])) {
        parsedFnCall <- parsed[[1]]
        parsedFnCall$es <- parsedFnCall$es[[3]]
        rawFnCall <- paste(deparse(parsedFnCall), collapse = '')
        myHistory <- paste(complexArguments, rawFnCall, sep="\n")
    } else {
        myHistory <- paste(complexArguments, rds[[1]]$src, sep='\n')
    }

    if (!is.element(toString(fn), rootFn)) {
        parent <- parsed[[1]]$es[[2]]
        parentVar <- parsed[[1]]$es[[3]]
        parentHistory <- reproduceInR(parent, leaf = F, step = step + 1, savedEnv = savedEnv)
        myHistory <- paste(parentHistory, myHistory, sep='\n')
    }

    if (leaf) {
        assign('env', savedEnv, envir = parent.frame())
        myHistory <- paste('library(phantasus)', 'load(\'~/Downloads/env.rda\') # Please note', myHistory, sep = '\n')
        return(jsonlite::toJSON(myHistory))
    }
    myHistory
}
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API