Crop a raster file in R
Create a box as a Spatial object and crop your raster by the box.
e <- as(extent(-16, -7.25, 4, 12.75), 'SpatialPolygons')
crs(e) <- "+proj=longlat +datum=WGS84 +no_defs"
r <- crop(worldpopcount, e)
From the raster
package documentation,
library(raster)
r <- raster(nrow=45, ncol=90)
r[] <- 1:ncell(r)
# crop Raster* with Spatial* object
b <- as(extent(6, 6.4, 49.75, 50), 'SpatialPolygons')
crs(b) <- crs(r)
rb <- crop(r, b)