Skip to content

Commit

Permalink
fixed the broken R file generation
Browse files Browse the repository at this point in the history
When using the R script, one has to provide the name of package in double quotes.
  • Loading branch information
chinmayshah99 committed Feb 13, 2021
1 parent b0dba9c commit f015505
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions r_freeze/r_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ def write_package_file(packages: List[str], file_name: str, overwrite: bool = Fa
Raises:
FileExistsError: If the outfile already exists (incase not overwriting)
"""
# if the file already exists and overwrite flag is false, raise an error
if os.path.isfile(file_name) and not overwrite:
raise FileExistsError("File already exists")
# if file name exists, create a new file

# if the output file is a R file, create a proper R script
if file_name[-1] == "R":
with open(file_name, mode="w", encoding="utf-8") as f:
for item in packages:
f.write("install.packages(%s)\n" % item)
f.write('install.packages("%s")\n' % item)
# incase the output file is not a R file, just print it out as a list of packages
else:
with open(file_name, mode="w", encoding="utf-8") as f:
for item in packages:
Expand Down

0 comments on commit f015505

Please sign in to comment.