The solution presented by Duccio resets the spacing on every new segment. I adapted the script to a version that does a running spacing. The difference is visualized in the images below.
Splitting as done in the approach by Duccio
The desired spacing (represented by length of green bar) always begins at each segment. Residual distances from the previous segments are not transferred to the next segment. Thus, the resulting spacing is not constant over the full line. 
Splitting as done in my approach
The desired spacing is transferred arround corners. This approach garantuees that the points have always the desired spacing with regard to the original line. However, neither here is the spacing of the resulting points to each other constant. Furthermore, this approach produces a line shorter than the original line. 
This effect decreases with a higher resolution. 


Or can be prevented by setting the optional parameter "add_original_points" to TRUE. 
Note: the "right algorithm to use" depends on your application.
Disclaimer: my version is entirely based on the solution by Duccio A and I give him full credit.
My approach does not use Line objects (sp package) but works entirely on data frames. Thus, I would not want to fork the original github repos.
The full code is:
resample_polyline = function(polyline, interval_length = 20, add_original_points = TRUE, add_final_point = FALSE) {
# The function splits a polyline into segments of a given length.
# polyline: a spatial polyline data frame
# interval_length: the length of the segments to split the lines into, in units of the polyline coordinates
# add_original_points: whether or not the original points of the polyline should be added to the resulting line
# if set FALSE, the resulting line will be shorter
# add_final_point: whether or not the final point of the polyline should be added to the resulting line
# transform input polyline
linedf = data.frame(
x = polyline$x[1:nrow(polyline)-1],
y = polyline$y[1:nrow(polyline)-1],
x2 = polyline$x[2:nrow(polyline)],
y2 = polyline$y[2:nrow(polyline)]
)
# prepare output
df = data.frame(
x = numeric(),
y = numeric()
)
residual_seg_length = 0
for (i in 1:nrow(linedf)) {
# for each line of the dataframe calculate segment length
v_seg = linedf[i, ]
seg_length = sqrt((v_seg$x - v_seg$x2) ^ 2 + (v_seg$y - v_seg$y2) ^ 2)
# create a vector of direction for the segment
v = c(v_seg$x2 - v_seg$x, v_seg$y2 - v_seg$y)
# unit length
u = c(v[1] / sqrt(v[1] ^ 2 + v[2] ^ 2), v[2] / sqrt(v[1] ^ 2 + v[2] ^ 2))
# calculate number of segment the segment is split into
num_seg = floor((seg_length - residual_seg_length) / interval_length)
# skip if next vertex is before interval_length
if(num_seg >= 0) {
# add interpolated segments
for (i in 0:(num_seg)) {
df[nrow(df) + 1,] = c(
v_seg$x + u[1] * residual_seg_length + u[1] * interval_length * i ,
v_seg$y + u[2] * residual_seg_length + u[2] * interval_length * i
)
}
# add original point (optional)
if(add_original_points){
df[nrow(df) + 1,] = c(
v_seg$x2,
v_seg$y2
)
}
} else {
# add original point (optional)
if(add_original_points){
df[nrow(df) + 1,] = c(
v_seg$x2,
v_seg$y2
)
}
residual_seg_length = residual_seg_length - seg_length
next()
}
# calculate residual segment length
residual_seg_length = interval_length - ((seg_length - residual_seg_length) - (num_seg * interval_length))
}
# add final point (optional)
if(add_final_point){
df = rbind(df, data.frame(
x = tail(polyline$x, n=1),
y = tail(polyline$y, n=1)
))
}
return(df)
}
Test it with
polyline = data.frame(
x = c(-5,1,5,7,8,12,14,16,17,13), # x
y = c(0,11,3,8,2,15,9,13,15,23) # y
)
plot(polyline$x, polyline$y, type="l", asp=1, lwd=1)
points(polyline$x, polyline$y, pch=4, cex=4, col="gray")
polyline2 = resample_polyline(polyline, interval_length = 5, add_final_point = FALSE, add_original_points = TRUE)
lines(polyline2$x, polyline2$y, col="red", lty=4, lwd=3)
points(polyline2$x, polyline2$y, pch=19)
legend("topleft",
c("original points", "added points", "resulting line"),
pch = c(4, 19, NA),
lty = c(NA, NA, 2),
pt.cex = c(4,1,1),
col = c("gray", "black", "red")
)