diff --git a/com.oracle.truffle.r.native/run/Makefile b/com.oracle.truffle.r.native/run/Makefile index 7da133d1607f1b85524a6bb32ad91969928af10d..f3eec5d3a138741f717912f57d4144d280e1d6a1 100644 --- a/com.oracle.truffle.r.native/run/Makefile +++ b/com.oracle.truffle.r.native/run/Makefile @@ -32,8 +32,9 @@ .PHONY: bindir all rcmd FASTR_R_HOME := $(abspath $(TOPDIR)/..) -FASTR_BINDIR = $(FASTR_R_HOME)/bin -FASTR_ETCDIR = $(FASTR_R_HOME)/etc +FASTR_BIN_DIR := $(FASTR_R_HOME)/bin +FASTR_ETC_DIR := $(FASTR_R_HOME)/etc +FASTR_SHARE_DIR := $(FASTR_R_HOME)/share R_SCRIPT := $(addprefix $(GNUR_HOME)/bin/,R) SUPPORT_SCRIPTS := $(addprefix $(GNUR_HOME)/bin/,BATCH COMPILE INSTALL Rcmd) @@ -41,27 +42,35 @@ SUPPORT_SCRIPTS := $(addprefix $(GNUR_HOME)/bin/,BATCH COMPILE INSTALL Rcmd) # Not all of these work unchanged ETC_FILES := $(addprefix $(GNUR_HOME)/etc/,javaconf,ldpaths,Renviron,repositories) +SHARE_FILES := $(addprefix $(GNUR_HOME)/share/,R) + all: rundirs rcmds rundirs: - mkdir -p $(FASTR_BINDIR) - mkdir -p $(FASTR_BINDIR)/exec - mkdir -p $(FASTR_ETCDIR) + mkdir -p $(FASTR_BIN_DIR) + mkdir -p $(FASTR_BIN_DIR)/exec + mkdir -p $(FASTR_ETC_DIR) + mkdir -p $(FASTR_SHARE_DIR) -rcmds: $(FASTR_BINDIR)/R +rcmds: $(FASTR_BIN_DIR)/R -$(FASTR_BINDIR)/R: Makefile R.sh Rscript.sh Rscript_exec.sh - cp R.sh $(FASTR_BINDIR)/exec/R - cp Rscript_exec.sh $(FASTR_BINDIR)/exec/Rscript - cp Rscript.sh $(FASTR_BINDIR)/Rscript - chmod +x $(FASTR_BINDIR)/exec/R $(FASTR_BINDIR)/exec/Rscript $(FASTR_BINDIR)/Rscript - cp $(SUPPORT_SCRIPTS) $(FASTR_BINDIR) - sed -e 's!\(^R_HOME_DIR=\)\(.*\)!\1"$(FASTR_R_HOME)"!' < $(R_SCRIPT) > $(FASTR_BINDIR)/R - chmod +x $(FASTR_BINDIR)/R - touch $(FASTR_ETCDIR)/ldpaths - cp $(GNUR_HOME)/etc/Renviron $(FASTR_ETCDIR) - cp Makeconf.etc $(FASTR_ETCDIR)/Makeconf +$(FASTR_BIN_DIR)/R: Makefile R.sh Rscript.sh Rscript_exec.sh + cp R.sh $(FASTR_BIN_DIR)/exec/R + cp Rscript_exec.sh $(FASTR_BIN_DIR)/exec/Rscript + cp Rscript.sh $(FASTR_BIN_DIR)/Rscript + chmod +x $(FASTR_BIN_DIR)/exec/R $(FASTR_BIN_DIR)/exec/Rscript $(FASTR_BIN_DIR)/Rscript + cp $(SUPPORT_SCRIPTS) $(FASTR_BIN_DIR) + sed -e 's!\(^R_HOME_DIR=\)\(.*\)!\1"$(FASTR_R_HOME)"!' < $(R_SCRIPT) > $(FASTR_BIN_DIR)/R + chmod +x $(FASTR_BIN_DIR)/R + touch $(FASTR_ETC_DIR)/ldpaths + sed -e "s|\(R_LIBS_USER=.*-'\)\(.*\)'}|\1$(FASTR_R_HOME)/library'}|" < $(GNUR_HOME)/etc/Renviron > $(FASTR_ETC_DIR)/Renviron + cp Makeconf.etc $(FASTR_ETC_DIR)/Makeconf + cp -r $(SHARE_FILES) $(FASTR_SHARE_DIR) + # overrides + cp examples-header.R examples-footer.R $(FASTR_SHARE_DIR)/R clean: - rm -rf $(FASTR_BINDIR) - rm -f Makeconf.etc + rm -rf $(FASTR_BIN_DIR) + rm -rf $(FASTR_ETC_DIR) + rm -rf $(FASTR_SHARE_DIR) + \ No newline at end of file diff --git a/com.oracle.truffle.r.native/run/examples-footer.R b/com.oracle.truffle.r.native/run/examples-footer.R new file mode 100644 index 0000000000000000000000000000000000000000..d9611537dc3f5bc32c034203e62e17d4e8f4822d --- /dev/null +++ b/com.oracle.truffle.r.native/run/examples-footer.R @@ -0,0 +1,11 @@ +### * <FOOTER> +### +options(digits = 7L) +base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n") +#grDevices::dev.off() +### +### Local variables: *** +### mode: outline-minor *** +### outline-regexp: "\\(> \\)?### [*]+" *** +### End: *** +quit('no') diff --git a/com.oracle.truffle.r.native/run/examples-header.R b/com.oracle.truffle.r.native/run/examples-header.R new file mode 100644 index 0000000000000000000000000000000000000000..bafb5968808f0a7e41d637027bb29820620b0387 --- /dev/null +++ b/com.oracle.truffle.r.native/run/examples-header.R @@ -0,0 +1,66 @@ +### * <HEADER> +### +attach(NULL, name = "CheckExEnv") +assign("nameEx", + local({ + s <- "__{must remake R-ex/*.R}__" + function(new) { + if(!missing(new)) s <<- new else s + } + }), + pos = "CheckExEnv") +### Add some hooks to label plot pages for base and grid graphics +#assign("base_plot_hook", +# function() { +# pp <- graphics::par(c("mfg","mfcol","oma","mar")) +# if(all(pp$mfg[1:2] == c(1, pp$mfcol[2]))) { +# outer <- (oma4 <- pp$oma[4]) > 0; mar4 <- pp$mar[4] +# graphics::mtext(sprintf("help(\"%s\")", nameEx()), side = 4, +# line = if(outer)max(1, oma4 - 1) else min(1, mar4 - 1), +# outer = outer, adj = 1, cex = 0.8, col = "orchid", las = 3) +# } +# }, +# pos = "CheckExEnv") +#assign("grid_plot_hook", +# function() { +# grid::pushViewport(grid::viewport(width=grid::unit(1, "npc") - +# grid::unit(1, "lines"), x=0, just="left")) +# grid::grid.text(sprintf("help(\"%s\")", nameEx()), +# x=grid::unit(1, "npc") + grid::unit(0.5, "lines"), +# y=grid::unit(0.8, "npc"), rot=90, +# gp=grid::gpar(col="orchid")) +# }, +# pos = "CheckExEnv") +#setHook("plot.new", get("base_plot_hook", pos = "CheckExEnv")) +#setHook("persp", get("base_plot_hook", pos = "CheckExEnv")) +#setHook("grid.newpage", get("grid_plot_hook", pos = "CheckExEnv")) +assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + .CheckExEnv <- as.environment("CheckExEnv") + delayedAssign("T", stop("T used instead of TRUE", domain = NA), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE", domain = NA), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + if(length(newitems)) tools:::detachPackages(newitems) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path", domain = NA) + }, + pos = "CheckExEnv") +assign("ptime", proc.time(), pos = "CheckExEnv") +## Do this before loading the package, +## since packages have been known to change settings. +## Force a size that is close to on-screen devices, fix paper. +## don't rename par.postscript for back-compatibility of reference output. +#grDevices::pdf.options(width = 7, height = 7, paper = "special", reset = TRUE) +#grDevices::pdf(paste(pkgname, "-Ex.pdf", sep=""), encoding = "ISOLatin1") +# +#assign("par.postscript", graphics::par(no.readonly = TRUE), pos = "CheckExEnv") +#options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly"))