title: How to extract a substring based on a central element and length added on both sides? Fill X, if the central element is too close to string end
body: <p>I have a string and I would like to extract a substring from it. The way I want to specify substring is</p>
  
  <p>1) by the position of the central element 
  2) by the number of elements I want on both sides</p>
  
  <p>E.g. "BBABBB", I would like a substring at position 3 and length of 1 on both sides, which makes "BAB". The tricky part is that if the number of elements is too low I would like to add X. E.g. if I say central position 3 and 3 elements each side, I would like XBBABBB. Is there a function that does it already in R?</p>