diff --git a/examples/src/main/r/ml/als.R b/examples/src/main/r/ml/als.R
index 383bbba1908eb0a487b0527765c7891a6491b711..4d1c91add54e1805d5f005e4293b5d0f08ce74c6 100644
--- a/examples/src/main/r/ml/als.R
+++ b/examples/src/main/r/ml/als.R
@@ -41,5 +41,7 @@ summary(model)
 
 # Prediction
 predictions <- predict(model, test)
-showDF(predictions)
+head(predictions)
 # $example off$
+
+sparkR.session.stop()
diff --git a/examples/src/main/r/ml/bisectingKmeans.R b/examples/src/main/r/ml/bisectingKmeans.R
index 37aeb74fc7612e6dc753a1399ef9f4d38e9c1470..5fb5bfb0fa5a38084f87af32fab0976908c44e24 100644
--- a/examples/src/main/r/ml/bisectingKmeans.R
+++ b/examples/src/main/r/ml/bisectingKmeans.R
@@ -40,3 +40,5 @@ summary(fitted.model)
 fitted <- predict(model, df)
 head(select(fitted, "Sepal_Length", "prediction"))
 # $example off$
+
+sparkR.session.stop()
diff --git a/examples/src/main/r/ml/gaussianMixture.R b/examples/src/main/r/ml/gaussianMixture.R
index 54b69acc83d97234a542179360877f91cf252294..558e44cc112ec5cd47b00f4b6dca6a395773e0ad 100644
--- a/examples/src/main/r/ml/gaussianMixture.R
+++ b/examples/src/main/r/ml/gaussianMixture.R
@@ -38,5 +38,7 @@ summary(model)
 
 # Prediction
 predictions <- predict(model, test)
-showDF(predictions)
+head(predictions)
 # $example off$
+
+sparkR.session.stop()
diff --git a/examples/src/main/r/ml/gbt.R b/examples/src/main/r/ml/gbt.R
index be16c2aa6633098c2467a1df5d2058ed9e0ffb55..bc654f1df7ab6d3d7135724896422c92e562fd00 100644
--- a/examples/src/main/r/ml/gbt.R
+++ b/examples/src/main/r/ml/gbt.R
@@ -40,7 +40,7 @@ summary(model)
 
 # Prediction
 predictions <- predict(model, test)
-showDF(predictions)
+head(predictions)
 # $example off:classification$
 
 # GBT regression model
@@ -59,5 +59,7 @@ summary(model)
 
 # Prediction
 predictions <- predict(model, test)
-showDF(predictions)
+head(predictions)
 # $example off:regression$
+
+sparkR.session.stop()
diff --git a/examples/src/main/r/ml/glm.R b/examples/src/main/r/ml/glm.R
index 599071790a2c3dba9219385356a01a90736f2a89..e41af97751d3f5df59175ca16bf7545083b08035 100644
--- a/examples/src/main/r/ml/glm.R
+++ b/examples/src/main/r/ml/glm.R
@@ -36,7 +36,7 @@ summary(gaussianGLM)
 
 # Prediction
 gaussianPredictions <- predict(gaussianGLM, gaussianTestDF)
-showDF(gaussianPredictions)
+head(gaussianPredictions)
 
 # Fit a generalized linear model with glm (R-compliant)
 gaussianGLM2 <- glm(Sepal_Length ~ Sepal_Width + Species, gaussianDF, family = "gaussian")
@@ -53,5 +53,7 @@ summary(binomialGLM)
 
 # Prediction
 binomialPredictions <- predict(binomialGLM, binomialTestDF)
-showDF(binomialPredictions)
+head(binomialPredictions)
 # $example off$
+
+sparkR.session.stop()
diff --git a/examples/src/main/r/ml/isoreg.R b/examples/src/main/r/ml/isoreg.R
index 75dce97ed99312cb5e156b9da816f14df620d1ff..a53c83eac430756afdec35dec53a651f0f384f80 100644
--- a/examples/src/main/r/ml/isoreg.R
+++ b/examples/src/main/r/ml/isoreg.R
@@ -38,5 +38,7 @@ summary(model)
 
 # Prediction
 predictions <- predict(model, test)
-showDF(predictions)
+head(predictions)
 # $example off$
+
+sparkR.session.stop()
diff --git a/examples/src/main/r/ml/kmeans.R b/examples/src/main/r/ml/kmeans.R
index 043b21b0385d7d1c9f95923a3b055e5aec617b3a..288e2f9724e0030ca17dc53f69a90c9cea4201d6 100644
--- a/examples/src/main/r/ml/kmeans.R
+++ b/examples/src/main/r/ml/kmeans.R
@@ -36,9 +36,11 @@ kmeansModel <- spark.kmeans(kmeansDF, ~ Sepal_Length + Sepal_Width + Petal_Lengt
 summary(kmeansModel)
 
 # Get fitted result from the k-means model
-showDF(fitted(kmeansModel))
+head(fitted(kmeansModel))
 
 # Prediction
 kmeansPredictions <- predict(kmeansModel, kmeansTestDF)
-showDF(kmeansPredictions)
+head(kmeansPredictions)
 # $example off$
+
+sparkR.session.stop()
diff --git a/examples/src/main/r/ml/kstest.R b/examples/src/main/r/ml/kstest.R
index 12625f7d3e635bbf63cafa6a9825e95e6b60df96..e2b07702b6f3aef97dc9dccc2316c0fda8488a4f 100644
--- a/examples/src/main/r/ml/kstest.R
+++ b/examples/src/main/r/ml/kstest.R
@@ -37,3 +37,5 @@ model <- spark.kstest(df, "test", "norm")
 # Model summary
 summary(model)
 # $example off$
+
+sparkR.session.stop()
diff --git a/examples/src/main/r/ml/lda.R b/examples/src/main/r/ml/lda.R
index 7b187d155a4cbbedb9550859c16d1b744b457d0b..769be0a78dfb6842e6b2ad2e6fb25c97857b586f 100644
--- a/examples/src/main/r/ml/lda.R
+++ b/examples/src/main/r/ml/lda.R
@@ -38,9 +38,11 @@ summary(model)
 
 # Posterior probabilities
 posterior <- spark.posterior(model, test)
-showDF(posterior)
+head(posterior)
 
 # The log perplexity of the LDA model
 logPerplexity <- spark.perplexity(model, test)
 print(paste0("The upper bound bound on perplexity: ", logPerplexity))
 # $example off$
+
+sparkR.session.stop()
diff --git a/examples/src/main/r/ml/logit.R b/examples/src/main/r/ml/logit.R
index a2ac882ed022c2c3a3fc1099dbe2add84151a512..4c8fd428d3852f4c052458f7dd9b88ae73a86a64 100644
--- a/examples/src/main/r/ml/logit.R
+++ b/examples/src/main/r/ml/logit.R
@@ -40,7 +40,7 @@ summary(model)
 
 # Prediction
 predictions <- predict(model, test)
-showDF(predictions)
+head(predictions)
 # $example off:binomial$
 
 # Multinomial logistic regression
@@ -59,5 +59,7 @@ summary(model)
 
 # Prediction
 predictions <- predict(model, test)
-showDF(predictions)
+head(predictions)
 # $example off:multinomial$
+
+sparkR.session.stop()
diff --git a/examples/src/main/r/ml/ml.R b/examples/src/main/r/ml/ml.R
index 05f5199aebe1572264f5f061fee04e3cf8a2811a..b96819418bad3eb2559c77941245df77f18597ab 100644
--- a/examples/src/main/r/ml/ml.R
+++ b/examples/src/main/r/ml/ml.R
@@ -42,7 +42,7 @@ summary(gaussianGLM2)
 
 # Check model prediction
 gaussianPredictions <- predict(gaussianGLM2, gaussianTestDF)
-showDF(gaussianPredictions)
+head(gaussianPredictions)
 
 unlink(modelPath)
 # $example off:read_write$
diff --git a/examples/src/main/r/ml/mlp.R b/examples/src/main/r/ml/mlp.R
index d28fc069bd118a91fbf78f2dd62650d6b9485a44..b69ac845f2dbd3357ef5f569da96c5fd27b5a2df 100644
--- a/examples/src/main/r/ml/mlp.R
+++ b/examples/src/main/r/ml/mlp.R
@@ -44,5 +44,7 @@ summary(model)
 
 # Prediction
 predictions <- predict(model, test)
-showDF(predictions)
+head(predictions)
 # $example off$
+
+sparkR.session.stop()
diff --git a/examples/src/main/r/ml/naiveBayes.R b/examples/src/main/r/ml/naiveBayes.R
index 9c416599b4d78f8d78bcf54f014b9602b688bc39..da69e93ef294e5e0162b61609d6fe194ac048859 100644
--- a/examples/src/main/r/ml/naiveBayes.R
+++ b/examples/src/main/r/ml/naiveBayes.R
@@ -37,5 +37,7 @@ summary(nbModel)
 
 # Prediction
 nbPredictions <- predict(nbModel, nbTestDF)
-showDF(nbPredictions)
+head(nbPredictions)
 # $example off$
+
+sparkR.session.stop()
diff --git a/examples/src/main/r/ml/randomForest.R b/examples/src/main/r/ml/randomForest.R
index d1b96b62a0e3b8cb6f9bf2d032959f2f123589ec..5d99502cd971de519a1d29a9f59babb40b9ebf97 100644
--- a/examples/src/main/r/ml/randomForest.R
+++ b/examples/src/main/r/ml/randomForest.R
@@ -40,7 +40,7 @@ summary(model)
 
 # Prediction
 predictions <- predict(model, test)
-showDF(predictions)
+head(predictions)
 # $example off:classification$
 
 # Random forest regression model
@@ -59,5 +59,7 @@ summary(model)
 
 # Prediction
 predictions <- predict(model, test)
-showDF(predictions)
+head(predictions)
 # $example off:regression$
+
+sparkR.session.stop()
diff --git a/examples/src/main/r/ml/survreg.R b/examples/src/main/r/ml/survreg.R
index f728b8b5d8c06d1ce806c7ea5e37171e05227285..bf6c0a161943f45abdb3884b8c2bd1d4460e6a35 100644
--- a/examples/src/main/r/ml/survreg.R
+++ b/examples/src/main/r/ml/survreg.R
@@ -39,5 +39,7 @@ summary(aftModel)
 
 # Prediction
 aftPredictions <- predict(aftModel, aftTestDF)
-showDF(aftPredictions)
+head(aftPredictions)
 # $example off$
+
+sparkR.session.stop()