Code moves electrons in and out of the MCU's pins. Electrons and Pins are paramount.
Often it is unpleasant to see the pins assigned behind the scenes ( not in main). Like I2C and SPI that have PINs defaulted to Ex D1 D2. This misdirection is quickly learned and when pins aren't explicitly declared the prime directive is to dig them out before using any library routine.
With multiple boards the fact that the board selection is an IDE option and not a code option is unfortunate and requires a work around
To avoid compilation to the wrong MCU esp8266 or esp32 ....code like this is necessary as the first line in main
#if !(defined( ARDUINO_ARCH_ESP8266))
#error Oops! Make sure you have 'ESP8266' compatible board selected from the 'Tools -> Boards' menu.
#endif
Issue
A more perfect workaround would be to specify compilation to a specific board like WeMos D1 R2.
Does anyone Know how to do this?