Code works fine with R Script, but does not run with knitr

Could you ask this with a minimal REPR oducible EX ample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.