1
#  lazyvec - R package for creating, testing and deploying custom ALTREP vectors
2
#
3
#  Copyright (C) 2019-present, Mark AJ Klik
4
#
5
#  This file is part of the lazyvec R package.
6
#
7
#  The lazyvec R package is free software: you can redistribute it and/or modify it
8
#  under the terms of the GNU Affero General Public License version 3 as
9
#  published by the Free Software Foundation.
10
#
11
#  The lazyvec R package is distributed in the hope that it will be useful, but
12
#  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
#  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
14
#  for more details.
15
#
16
#  You should have received a copy of the GNU Affero General Public License along
17
#  with the lazyvec R package. If not, see <http://www.gnu.org/licenses/>.
18
#
19
#  You can contact the author at:
20
#  - lazyvec R package source repository : https://github.com/fstpackage/lazyvec
21

22

23
#' Generate a fully functional lazyvec implementation from a selection of examples
24
#'
25
#' With this method you can generate a single-file sample implementation of a lazyvec.
26
#' This sample implementation can be used as a starting point for custom implementations.
27
#' For a detailed description of the sample implementations, please see the corresponding
28
#' vignette.
29
#' 
30
#' The following sample implementations are available:
31
#' * _integer_range_: an integer range with a custom step size
32
#' * _real_range_: a range of double's with a custom step size
33
#' * _logical_compressed_: a compressed logical vector
34
#' * _raw_ondisk_: a file based out-of-memory raw vector
35
#' * _character_range_: the character vector equivalent of an integers range n:m
36
#'
37
#' @param skeleton_id id of the sample implementation. Valid id's are:
38
#' @param path path to the target file
39
#'
40
#' @export
41
#'
42
#' @md
43
lazyvec_skeleton <- function(skeleton_id, path) {
44 3
  sample_dir <- paste0(path.package("lazyvec"), "/", "lazyvec_samples/")
45

46 3
  lazyvec_sample_copy(skeleton_id, sample_dir, path)
47
}
48

49

50
# helper method to allow for alternative sample folders
51
lazyvec_sample_copy <- function(skeleton_id, sample_dir, path) {
52 3
  valid_ids <- c("integer_range")
53

54 3
  if (!(skeleton_id %in% valid_ids)) {
55 3
    stop("Invalid skeleton_id. Please select one of the following id's: '",
56 3
      paste(valid_ids[1:length(valid_ids) - 1], collapse = "', '"), "' or '", tail(valid_ids, 1), "'.")
57
  }
58

59 3
  if (file.exists(path)) {
60 3
    stop("target path already exists, please select a path to a non-existing file")
61
  }
62

63 3
  if (!dir.exists(dirname(path))) {
64 3
    stop("target path points to a non-existing folder, please create the folder first")
65
  }
66

67 3
  sample_path <- paste0(sample_dir, skeleton_id, ".R")
68

69 3
  file.copy(sample_path, path)
70

71 3
  invisible(NULL)
72
}

Read our documentation on viewing source code .

Loading