R/scriptdir.R

Defines functions scriptdir

scriptdir <- function() {
  # Get scriptdir using Python
  #
  # Arguments:
  #   nothing
  #
  # Returns:
  #   nothing

  # Write Python file in current directory
  pytmp = "pytmp.py"
  pyscript = c(
    "from os.path import dirname, realpath",
    "print(dirname(realpath(__file__)))"
  )
  writeLines(pyscript, con = pytmp)

  # Run Python file and capture result
  work = system(sprintf('python "%s"', pytmp), intern = TRUE)
  
  # Remove temporary file
  if (file.exists(pytmp)) file.remove(pytmp)
  
  return(work)
}
tsouchlarakis/rdoni documentation built on Sept. 16, 2019, 8:53 p.m.