Skip to content

Commit

Permalink
add flag to specify custom R library instead of /usr/lib/R/lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Foreman committed Apr 8, 2015
1 parent 4aa5c5c commit ef0694d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion magic/PyMB_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def __init__(self, shell):
location of R shared library
Note: R must be built with shared libraries
See http://stackoverflow.com/a/13224980/1028347''')
@argument('-LR', '--R_LIB', type=str, default='/usr/share/R/include',
help='''R_LIB : str, default '/usr/lib/R/lib'
location of R library
Note: R must be built with shared libraries
See http://stackoverflow.com/a/13224980/1028347''')
@argument('-CC', '--CCOMPILER', type=str, default='g++',
help='''CCOMPILER : str, default 'g++'
C++ compiler to use''')
Expand Down Expand Up @@ -95,7 +100,7 @@ def PyMB(self, line, cell):
code += '}\n'

# compile model
model.compile(codestr=code, output_dir=args.OUTPUT_DIR, cc=args.CCOMPILER, R=args.R_DIR, TMB=args.TMB_DIR, verbose=args.VERBOSE)
model.compile(codestr=code, output_dir=args.OUTPUT_DIR, cc=args.CCOMPILER, R=args.R_DIR, TMB=args.TMB_DIR, LR=args.R_LIB, verbose=args.VERBOSE)

# print if verbose
if args.VERBOSE == True:
Expand Down
4 changes: 2 additions & 2 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self, name=None, filepath=None, codestr=None, **kwargs):

def compile(self, filepath=None, codestr=None, output_dir='tmb_tmp',
cc='g++', R='/usr/share/R/include',
TMB='/usr/local/lib/R/site-library/TMB/include', verbose=False):
TMB='/usr/local/lib/R/site-library/TMB/include', LR='/usr/lib/R/lib', verbose=False):
'''
Compile TMB C++ code and load into R
Expand Down Expand Up @@ -137,7 +137,7 @@ def compile(self, filepath=None, codestr=None, output_dir='tmb_tmp',
options='-shared',
so='{output_dir}/{name}.so'.format(output_dir=output_dir, name=self.name),
o='{output_dir}/{name}.o'.format(output_dir=output_dir, name=self.name),
link='-L/usr/lib/R/lib -lR')
link='-L{LR} -lR'.format(LR=LR))
try:
cmnd_output = subprocess.check_output(link, stderr=subprocess.STDOUT, shell=True)
except subprocess.CalledProcessError as exc:
Expand Down

0 comments on commit ef0694d

Please sign in to comment.