A railway line in Yorkshire is set to be closed for two weeks after a hole opened up beneath the tracks.