Skip to content

Commit

Permalink
Only install devtools if package with version is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
langmm committed Sep 15, 2023
1 parent 212ea35 commit 427470a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions yggdrasil/languages/R/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ def install_packages(package_list, update=False, repos=None, **kwargs):
args = ('repos=\"%s\"' % repos
+ ("," if x.get('args', '') else "")
+ x.get('args', ''))
install_method = 'install.packages'
before_install = ''
install_method = []
if 'ver' in x:
R_cmd += [
before_install = [
"if (!is.element(\"devtools\", installed.packages()[,1])) {",
f' install.packages("devtools", repos="{repos}", '
f'dependencies=TRUE)',
Expand All @@ -198,12 +199,16 @@ def install_packages(package_list, update=False, repos=None, **kwargs):
R_cmd += [
f"if (is.element(\"{x['name']}\", installed.packages()[,1])) {{",
f" remove.packages(\"{x['name']}\")",
'}',
'}']
R_cmd += before_install
R_cmd += [
f"{install_method}({name}, {args})"]
else:
R_cmd += [
f"if (!is.element(\"{x['name']}\", installed.packages()[,1])) {{",
f"{install_method}({name}, {args})",
f"if (!is.element(\"{x['name']}\", installed.packages()[,1])) {{"]
R_cmd += [' ' + iline for iline in before_install]
R_cmd += [
f" {install_method}({name}, {args})",
'} else {',
f" print(\"{x['name']} already installed.\")",
'}']
Expand Down

0 comments on commit 427470a

Please sign in to comment.