Skip to contents

Shorthand to return a re-sample number of rows in a data frame by unique column

Usage

duplicate(file, new.name, pattern = NULL, replacement = NULL, open = TRUE)

Arguments

file

data frame to re-sample

new.name

column to uniquely re-sample

pattern

number of rows to return

replacement

unique numeric value for reproducibility

open

description

Value

data frame containing re-sampled rows from an original data frame

Examples

# \donttest{
if(interactive()){
# example to duplicate a file, and replace text1 within it
# NOTE that, by default, this function will also open the file within RStudio

#create sample file
file1s <- paste0(tempfile(),".R")
writeLines("message(
'Sample items: eggs, coke, fanta, book'
)", file1s)

file2s <- paste0(tempfile(),".R")
file3s <- paste0(tempfile(),".R")

duplicate(
  file = file1s,
  new.name = file2s,
  pattern = 'text1',
  replacement = 'replacement1'
 )

# duplicate the file, with multiple replacements
# replace 'book' with 'egg' and 'coke' with 'fanta'
duplicate(
  file1s, file2s,
  pattern = c('book','coke'),
  replacement = c('egg','fanta')
)



# duplicate the file with no replacement
duplicate(file1s,file3s) # this simply performs file.copy, and opens the new file



# duplicate the file but do not open for editing
duplicate(file1s,file3s, open = FALSE) # this does not open file after duplication
}
# }