You can use a function gsubfnthat you can provide a replacement function to replace content that matches the regular expression.
require(gsubfn)
gsubfn("0{3,}", function (x) paste(replicate(nchar(x), "1"), collapse=""), input)
You can replace paste(replicate(nchar(x), "1"), collapse="")with stri_dup("1", nchar(x))if you have the package installed stringi.
Or a more concise solution, as G. Grothendieck in the comment:
gsubfn("0{3,}", ~ gsub(".", 1, x), input)
Perl :
gsub("(?!\\A)\\G0|(?=0{3,})0", "1", input, perl=TRUE)
0, 0{3,}.
, , .