I've had good luck with the downloader pkg. It's a light wrapper around the base R downloading functions, Just replace the parts of those URL that will change. Doesn't look like you are using the ZIP:
library(downloader)
for( i in 1:3){
download.file( paste0("https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVinValues/",
VIN[i],"?format=csv&modelyear=",myear4[i]),
destfile=paste0("test_", i ,".csv"))}
#-------------------
trying URL 'https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVinValues/5XYPKDA55KG446393?format=csv&modelyear=2019'
Content type 'application/octet-stream' length 2352 bytes
==================================================
downloaded 2352 bytes
trying URL 'https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVinValues/5XYPHDA56KG443792?format=csv&modelyear=2019'
Content type 'application/octet-stream' length 2351 bytes
==================================================
downloaded 2351 bytes
trying URL 'https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVinValues/5XYPGDA33KG432573?format=csv&modelyear=2019'
Content type 'application/octet-stream' length 2349 bytes
==================================================
downloaded 2349 bytes
I'm not sure if the files would be guaranteed to have all the same columns but if they were you could read them into R with read.csv
and `do.call(rbind, ...) them together. There are lots of asked and answered questions about that part and multi-part questions are discouraged on SO, so I'm not thinking I should continue.