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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.