Code that runs RStudio's "Republish" button

I am working with a .Rmd file in RStudio. I have published a html file to RStudio's RPubs website. I will be republishing the same file to the same RPubs URL regularly. To do this I can press the 'Republish' button in the Viewer pane of RStudio.

But instead of pressing the 'Republish' button each time I want to republish, can I republish the file using code that is run at the end of the .Rmd file?

See this function in rsconnect: Upload a file to RPubs — rpubsUpload • rsconnect

That said, I would probably put the publishing code in its own script rather than having it be part of the content--it's not usually the case that you want to publish something every time you render the document locally.

I get below error when I run rpubsUpload. Know what problem is?

Error in curl::curl_fetch_memory(url, handle = handle) : 
  Stream error in the HTTP/2 framing layer [api.rpubs.com]: HTTP/2 stream 1 was not closed cleanly: INTERNAL_ERROR (err 2)

There's not enough information in your post for me to determine what might have produced that error. I'd need to see the code you actually ran, and it may be important to know what computer you're trying to run it from. your laptop? Workbench? Posit Cloud? something else?