Restricted Area "popping up" around you -- can it happen, and what do you do about it?
Assuming your question is for the US airspace.



Short answer:

When the activation periods cannot be totally anticipated, the description of the area must reference the possibility of activation announced by NOTAM. 

The NOTAM notice is normally not shorter than 4 hours before the activation.

While IFR flights will be prevented by ATC to enter or transit an active restricted area, non-controlled flights are under the sole responsibility of the pilot, as regard to flying within a restricted area.

A VFR pilot must take NOTAMs for restricted areas into account when preparing the flight (FSS), and should contact ATC when airborne for confirmation of the activation status.



From the pilot standpoint

You should not enter an inactive restricted area without contacting the controlling agency.

From AIM-3-4-3:


  Penetration of restricted areas without authorization from the using
  or controlling agency may be extremely hazardous to the aircraft and
  its occupants


You are not allowed to enter an active restricted area without prior permission.

From the Federal Register, 14 CFR Part 73, §73.13:


  No person may operate an aircraft within a restricted area between the
  designated altitudes and during the time of designation, unless he has
  the advance permission of (a) The using agency described in §73.15; or
  (b) The controlling agency described in §73.17.


FAA ATC, as the controlling agency, manages restricted area transit or avoidance, based on activation status, but only for IFR flights.

A pilot of a non-controlled flight (e.g. VFR) has the sole and complete responsibility for getting all information about the restrictions that may apply during its flight over a restricted area.

The briefing with FSS should include such research, contacting ATC prior to entering the restricted area seems the minimum.



From controlling / using agencies standpoint

A restricted area is part of the SUA (Special Use Airspace areas), and is jointly managed by Using and Controlling agencies.

Procedures for handling airspace matters, 21-2-4, Times of use:


  a. The times of use indicate the period during which the using agency
  is authorized to schedule and use a SUA area. These times should
  reflect when normal operations are expected to occur. In determining
  the times of use, the proponent should select the minimum period
  needed to meet the using agency's requirements. The goal is to capture
  the majority of the day-to-day activities. When the using agency has a
  requirement for intermittent, less frequent use of the airspace
  (outside the specific published timeperiod), a provision to activate
  the airspace by NOTAM may be stated in the SUA legal description.


What does that say? If some periods of activation cannot be anticipated, the phrasing "by NOTAM" must be used.


  
  NOTAM activation. Use "By NOTAM" or "Other Times by NOTAM" to 
  indicate when a NOTAM must be issued in order to activate the area.
  


Regarding the notice prior to activation by NOTAM:


  (e). NOTAMs should be issued as far in advance as feasible to ensure
  widest dissemination of the information to airspace users. Normally,
  the minimum advance notice should be at least 4 hours prior to the
  activation time.
  
  NOTE-  Under no circumstances may SUA be activated by
  a NOTAM unless the words "By NOTAM" or "other times by NOTAM" are
  stated in the area's legal description.


A 4-hour notice is the minimum usually accepted for the publication of the NOTAM prior to activation of the restricted area. I assume the exceptions would be handled on a case by case  basis.

An area without a NOTAM mention cannot be activated outside of the published periods. 

Example:

R-2305 Gila Bend, AZ
[...]
Time of designation 0700-2300 local time daily, other times by NOTAM.
Controlling agency FAA, Albuquerque ARTCC.
Using agency U.S. Air Force, 58th Fighter Wing, Luke AFB, AZ.




Related:


How to find out if Restricted Area is “hot” before taking off?
What should you do if you are forced to enter restricted or prohibited airspace?
Can gliders access restricted airspace?