How do I use a preprocess function for a node template?
Instead of using print_r() enable devel module and their new submodule called kint. And use kint() instead of print_r(). You can also use print_r() but is messy.


  How can I preprocess my variable array for a node template?


function YOURTHEME_preprocess_node(&amp;$variables){
  kint($variables);
}


If this does not work it might be a cache problem.  I will recommend you to set you website into dev mode using DrupalConsole. drupal site:mode dev

Why ?


  The Twig engine provides options for configuring debugging, automatic
  reloading (recompiling) of templates, and caching compiled templates
  in the filesystem. By default, the Twig theming engine compiles
  templates into PHP code and stores the compiled code in memory.
  Compiled code is unsuitable for development, since changes in Twig
  templates are not immediately updated in your Drupal site. Twig cache
  can be cleared through Drupal's clear cache interface, but for ongoing
  development it's easier to change Drupal's settings so that Twig
  doesn't cache anything at all.


Running  drupal site:mode dev will disable all twig cache. For more information about debugging please visit - Debugging compiled Twig templates