-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathinstall_windows.R
69 lines (63 loc) · 2.09 KB
/
install_windows.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
if(.Platform$OS.type != "windows")stop("This script is only for windows")
## ===== Default locations - change for non-standard setup
fileLocations <- function(){
rhome <- Sys.getenv("R_HOME")
rbin <- paste0(rhome,"/bin/",.Platform$r_arch)
rtools <- c("C:/Rtools",
"~/Rtools",
paste0(rhome,"/../../Rtools"),
paste0(rhome,"/../Rtools") )
gccbin <- paste0(rtools,"/gcc-4.6.3/bin")
gdbbin <- paste0(rtools,"/gcc-4.6.3/bin64")
ans <- list(rhome=rhome,rbin=rbin,rtools=rtools,gccbin=gccbin,gdbbin=gdbbin)
lapply(ans,function(x)x[file.exists(x)][1])
}
setPath <- function(...){
fl <- fileLocations()
## ===== Add R to PATH
path <- Sys.getenv("PATH")
path <- paste(path.expand(fl$rbin),path,sep=";")
## ===== Add gcc to PATH
if(is.na(fl$rtools))stop("Failed to locate Rtools folder")
path <- paste(path.expand(fl$gccbin),path,sep=";")
## ===== Add gdb to PATH
path <- paste(path.expand(fl$gdbbin),path,sep=";")
## ===== Add unix tools to PATH
cwpath <- paste0(path.expand(fl$rtools),"/bin")
path <- paste(cwpath,path,sep=";")
## ====== Update PATH
Sys.setenv(PATH=path)
## ====== Disable cygwin warnings
Sys.setenv(CYGWIN="nodosfilewarning")
}
createMakevars <- function(){
file <- "~/.R/Makevars"
if(file.exists(file))return(NULL)
dir.create("~/.R")
rhome <- Sys.getenv("R_HOME")
p <- paste0(rhome,"/etc/x64/Makeconf")
cat("Changing Makevars from\n")
x <- grep("-Wall",readLines(p),val=TRUE)
print(x)
x <- sub("-Wall ","",x)
x <- c(x,"PKG_CPPFLAGS += -DSUPPORT_OPENMP")
cat("to\n")
print(x)
writeLines(x,file)
}
modifyPathOnAttach <- function(){
winpath <- c("fileLocations<-",deparse(fileLocations),
"setPath<-",deparse(setPath),
".onAttach<-function(libname, pkgname){setPath()}")
writeLines(winpath,"spict/R/winpath.R")
}
if(!("spict" %in% installed.packages())){
setPath()
createMakevars()
modifyPathOnAttach()
shell("make install")
} else {
cat("spict already installed. To reinstall run:\n")
cat(" remove.packages(\"spict\")\n")
cat(" source(\"install_windows.R\")\n")
}