You can use the function Read.mnist() to read data and arrange them properly from MNIST dataset (the open handwriting digit database <http://yann.lecun.com/exdb/mnist/>). With this package, you can conveniently get all of necessary informations and then immediately start to check whether your machine learning algorithm works well. It can automatically recognize the type of dataset and returns the informations in corresponding structure.