High dynamic-range imagers aim to block out or null light from a very bright primary star to make it possible to detect and measure far fainter companions; in real systems a small fraction of the primary light is scattered, diffracted, and unocculted. We introduce S4, a flexible data-driven model for the unocculted (and highly speckled) light in the P1640 spectroscopic coronograph. The model uses Principal Components Analysis (PCA) to capture the spatial structure and wavelength dependence of the speckles but not the signal produced by any companion. Consequently, the residual typically includes the companion signal. The companion can thus be found by filtering this error signal with a fixed companion model. The approach is sensitive to companions that are of order a percent of the brightness of the speckles, or up to $10^{-7}$ times the brightness of the primary star. This outperforms existing methods by a factor of 2-3 and is close to the shot-noise physical limit.