Dear All,
I am looking for a way to make use of temporary files with the putpdf image command. Unfortunately, I find no way to make them understand each other. If the image is saved to a tempfile, the putpdf image command aborts with an error that the file type is not recognized (apparently it naively looks by the extension, and not by the actual contents, so fails on *.tmp files).
Saving the file as "`tmp'.png" is subject to two problems:
1. files are no longer temporary - they will not be deleted by Stata's tempfile tracker after the end of the code scope.
2. collisions are possible (and as a matter of fact likely) with files generated in previous runs, or in other sessions.
If in doubt, refer to the manual: "tempfile assigns names to the specified local macro names that may be used as names for temporary files. When the program or do-file concludes, any datasets created with these assigned names are erased."
Here "with these" means "exactly with these", not "derived from these".
Clearly adding the replace option is not a solution, as it hides the problem out of view, but doesn't solve it, and potentially can lead to incorrect reporting.
I see the following four ways of solving:
1. convince Stata to generate a temporary filename with a particular extension, in which case that could have been an option of the tempfile command, but there is none.
2. request Stata to create a temporary folder (not file, but folder) name, in which case I can be confident that my code owns the folder and can use fixed names (this would also be useful for my another project as well).
3. teach the putpdf to be more sophisticated and look into the contents of the file to determine it's type, or allow the user to specify it directly as an option, putpdf image ....., as(png).
4. teach graph save to save directly to the pdf document (do not confuse with saving as a pdf file, that's different).
All of these require intervention of the developers. Any advice from the fellow coders is much appreciated.
Best, Sergiy Radyakin
I am looking for a way to make use of temporary files with the putpdf image command. Unfortunately, I find no way to make them understand each other. If the image is saved to a tempfile, the putpdf image command aborts with an error that the file type is not recognized (apparently it naively looks by the extension, and not by the actual contents, so fails on *.tmp files).
Saving the file as "`tmp'.png" is subject to two problems:
1. files are no longer temporary - they will not be deleted by Stata's tempfile tracker after the end of the code scope.
2. collisions are possible (and as a matter of fact likely) with files generated in previous runs, or in other sessions.
If in doubt, refer to the manual: "tempfile assigns names to the specified local macro names that may be used as names for temporary files. When the program or do-file concludes, any datasets created with these assigned names are erased."
Here "with these" means "exactly with these", not "derived from these".
Clearly adding the replace option is not a solution, as it hides the problem out of view, but doesn't solve it, and potentially can lead to incorrect reporting.
I see the following four ways of solving:
1. convince Stata to generate a temporary filename with a particular extension, in which case that could have been an option of the tempfile command, but there is none.
2. request Stata to create a temporary folder (not file, but folder) name, in which case I can be confident that my code owns the folder and can use fixed names (this would also be useful for my another project as well).
3. teach the putpdf to be more sophisticated and look into the contents of the file to determine it's type, or allow the user to specify it directly as an option, putpdf image ....., as(png).
4. teach graph save to save directly to the pdf document (do not confuse with saving as a pdf file, that's different).
All of these require intervention of the developers. Any advice from the fellow coders is much appreciated.
Best, Sergiy Radyakin
Comment