~ubuntu-branches/debian/stretch/r-cran-rnexml/stretch

« back to all changes in this revision

Viewing changes to R/internal_nexml_id.R

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2016-04-08 13:58:39 UTC
  • Revision ID: package-import@ubuntu.com-20160408135839-ilq08z8v8p414qpn
Tags: upstream-2.0.6
ImportĀ upstreamĀ versionĀ 2.0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
nexml_env = new.env(hash=TRUE)
 
3
 
 
4
# If no prefix is given, will use a UUID
 
5
# Generates an id number by appending a counter to the prefix
 
6
# Will keep track of the counter for each prefix for that session.  
 
7
#' @import uuid
 
8
nexml_id <- function(prefix = "",
 
9
                     use_uuid = getOption("uuid", FALSE)){
 
10
  if(use_uuid){
 
11
      uid <- paste0("uuid-", UUIDgenerate())
 
12
  } else {
 
13
    if((prefix %in% ls(envir=nexml_env)))
 
14
      id_counter <- get(prefix, envir=nexml_env)
 
15
    else {
 
16
      assign(prefix, 1, envir=nexml_env)
 
17
      id_counter <- 1
 
18
    } 
 
19
 
 
20
    uid <- paste0(prefix, id_counter)
 
21
    id_counter <- id_counter + 1
 
22
    assign(prefix, id_counter, envir=nexml_env)
 
23
  }
 
24
  uid
 
25
}
 
26
 
 
27
#' reset id counter
 
28
#' 
 
29
#' reset the id counter
 
30
#' @export
 
31
reset_id_counter <- function(){
 
32
  rm(list=ls(envir=nexml_env), envir=nexml_env)
 
33
}
 
34
 
 
35
# use an environment to store counter