Fixes to reprun before Stata Conference#47
Conversation
|
@bbdaniels now it works, and stops at a different point. I'm not sure if it comes from the same issue. The line that produces the error is this (figure 4a runs perfectly, stops when adding the comment to introduce figure 4b, we can review this tomorrow). ` *Figure 4b below corresponds to Mean age of public paid employees, by industry: Health"` |
|
No, now it comes from Stata characters that are always problematic, namely: We just need to sanitize the command that's passed in somehow... @kbjarkefur ? I tried: but got: |
|
Solves #48 |
| local theline = regexr(`"`macval(line)'"',"[\[//]\\\^\%\|\?\*\+\(\)]","") | ||
| forv i = 1/10 { | ||
| local theline = regexr(`"`theline'"',"[\[//]]","") | ||
| local theline = regexr(`"`theline'"',"[\\]","") | ||
| local theline = regexr(`"`theline'"',"[\^]","") | ||
| local theline = regexr(`"`theline'"',"[\%]","") | ||
| local theline = regexr(`"`theline'"',"[\|]","") | ||
| local theline = regexr(`"`theline'"',"[\?]","") | ||
| local theline = regexr(`"`theline'"',"[\*]","") | ||
| local theline = regexr(`"`theline'"',"[\+]","") | ||
| local theline = regexr(`"`theline'"',"[\(]","") | ||
| local theline = regexr(`"`theline'"',"[\)]","") | ||
| // local theline = regexr(`"`theline'"',`"[\"]"',"") | ||
| } | ||
|
|
||
| foreach w in `macval(theline)' { | ||
| cap get_command, word(`"`w'"') |
There was a problem hiding this comment.
This section is attempting to sanitize strings to pass into get_command. It works decently should rather be a while loop most likely, and should probably put in spaces instead of blanks.
However, I can't figure out an appropriate handling for ". We cannot have unmatched " or the foreach line will break. At the same time, we cannot remove " because they are also needed to delineate words.
One solution @luisesanmartin proposed is to have a better handling for catching comments so they can be skipped here entirely. Another solution is to simply note failures here and fix them manually -- they are somewhat rare but @ankritisingh has encountered a couple (especially in comments, which is particularly painful).
Another solution is to take the handling of dofiles out of this loop, since we are only trying to catch do/run here. We could handle that separately in the full line if desired, rather than trying to catch the next word at this point.
There was a problem hiding this comment.
This is the unhandled *. Hence needing a while loop to catch them all. @luisesanmartin also interesting that catching comments won't help here!
There was a problem hiding this comment.
Also, it's possible that it's taking cmd"pdslasso alone as a word, which will still produce a lone " in the next step.
Get loop index correctly Solve #38
Handle quotes in sub-files
Flag when sub-do-file not found
Handle loops correctly with new command parser
| // Sanitize that string! -- see d17586d873a978987f34ba2fe536a311107ea58b for more regex | ||
| local theline = `"`macval(line)'"' | ||
| while regexm(`"`macval(theline)'"',"[\*]") { | ||
| local theline = regexr(`"`macval(theline)'"',"[\*]","") | ||
| } | ||
| while regexm(`"`macval(theline)'"',"\[//]"){ | ||
| local theline = regexr(`"`macval(theline)'"',"\[//]","") | ||
| } | ||
|
|
||
| // Identify all commands in line | ||
| foreach w in `macval(theline)' { | ||
| cap get_command, word(`"`w'"') |
There was a problem hiding this comment.
@kbjarkefur This is the best I could do here -- I cannot fix a single " yet.
There was a problem hiding this comment.
I'm still not 100% sure what an code example would be that is valid Stata code that have a single ". is there an example in the test files?
There was a problem hiding this comment.
This is one of the examples:
/* the do-file tests the "single quote
error"
*/
sysuse auto, clear
bys foreign: egen assigned = total(mpg)
There was a problem hiding this comment.
Similarly Ankriti had a file that included a line like:
* A very badly behaved comment "
There was a problem hiding this comment.
Here’s another example that produces the same error. However, it ran without issues in the previous version.
*** Load data (
sysuse auto, clear
There was a problem hiding this comment.
Yes, that’s the ( I suppose. Last time I wiped many more characters but I tried to minimize it this time. Can you provide a list of all characters which cause failure in this kind of example? You should be able to implement the fix since the code is templated right?
reprun before Stata Conference



Fix #46