Thanks for the reply but the issue is not the print part. It's that
p1 + geom_point()
does not print any data on the p1 background when used this way in a function in a package I'm building. It does work when I execute the code interactively. However, it does work when geom_point is tacked on to the ggplot statement directly ( ggplot() + geom_point() ). I assume it has something to do with aes() but I can't find out what or why.
I know. I'll work on coming up with something but the environment is a bit complex so I think it somehow is data dependent. I haven't come up with a good example and the trivial tests I've tried all work as you've exhibited above.
However, it seems like the p1 + geom_point() is not executing when it is on a line by itself. I know this makes no sense but that's what it seems like.
It is executed, but it's not saved.
you should use:
p1 = p1 + geom_point() to overwrite p1, so it can be recalled in the next step. You could also save it as p2 and then use print(p2).
hmm, okay that's true.
Still the invisible(print(p1)) statement in the next line overwrites the correct plot with the unfinished one as long as p1 doesn't include the added geom_point().