forked from USGS-R/grantools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_gran_repo.R
50 lines (33 loc) · 1.32 KB
/
add_gran_repo.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
#The text to be added to an .Rprofile file
repo_text = paste0('#Generated line by owi.usgs.gov/R/add_gran_repo.R: Do not edit by hand\n',
'options(repos=c(getOption(\'repos\'), USGS=\'http://owi.usgs.gov/R\'))\n')
#Check to see if they already have USGS repo setup
if(any(names(getOption('repos')) %in% 'USGS') | any(getOption('repos') %in% 'http://owi.usgs.gov/R')){
stop('You already have USGS:GRAN setup as a repository, skipping...')
}
#if not, find architecture and add accordingly
os = Sys.info()['sysname']
create_append_text = function(fpath, text, append){
write(text, fpath, append=append)
}
##DO FOR WINDOWS
if(os == 'Windows'){
rprofile_path = file.path(Sys.getenv("HOME"), '.Rprofile')
if(file.exists(rprofile_path)){
create_append_text(rprofile_path, repo_text, append=TRUE)
}else{
create_append_text(rprofile_path, repo_text, append=FALSE)
}
##DO FOR OS X
}else if(os == 'Darwin'){
rprofile_path = file.path(Sys.getenv("HOME"), '.Rprofile')
if(file.exists(rprofile_path)){
create_append_text(rprofile_path, repo_text, append=TRUE)
}else{
create_append_text(rprofile_path, repo_text, append=FALSE)
}
#Stop for all else
}else{
stop('Sorry, unable to automatically add GRAN on ', os)
}
cat('Your Rprofile has been updated to include GRAN.\nPlease restart R for changes to take effect.')