Need help understanding how to calculate the R value for LD1117
These regulators try to maintain their reference voltage (your Vr)(usually about 1.25 volts) between the output and adjust terminals, so your second calculation is correct.

However, in this world, nothing is perfect.  On Page 14 of the ST datasheet, the typical reference voltage is given as 1.25 volts, but it can vary between 1.238 volts and 1.262 volts (+/-1%), so, for any pair of resistors, the oubput voltage can vary +/- 1% - but the resistors also have a tolerance - often 5% (but 1% is quite common these days), so that will cause a further variation in output voltage. You will want to use standard resistor values, which will also adjust the output voltage a bit...

The Electrical Characteristics table lists a "Dropout voltage" (sometimes called "headroom") - this is the minimum diference between input and output voltages that will allow the regulaltor to operate.  In this case, if the regulator is supplying 100 mA, the input voltage should be at least 1.1 volts higher than the desired output voltage.  If the input voltage is too low, the device will be unable to regulate the output, and the output voltage will drop, probably keeping 1.1 volts across the regulator.