<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/security-the-dangers-of-copying-and-pasting-r-code/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://csgillespie.wordpress.com/2017/06/07/security-the-dangers-of-copying-and-pasting-r-code/"> R – Why?</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Most of the time when we stumble across a code snippet online, we often blindly copy and paste it into the R console. I suspect almost everyone does this. After all, what’s the harm? Consider this simple piece of R code that performs simple linear regression</p>
<pre># Generate data
x = rnorm(10)
y = rnorm(10)
</pre>
<div>message(“All your base are belong to us.”)</div>
<pre># Simple linear regression 
m = lm(y ~ x)
</pre>
<p>Now highlight the above piece of R code and copy and paste it into your console; <b>look</b> carefully at what you’ve pasted. A new line has magically appeared.</p>
<pre># Generate data
x = rnorm(10)
y = rnorm(10)
message(&quot;All your base are belong to us.&quot;)
# Simple linear regression
m = lm(y ~ x)
</pre>
<p>Due to some sneaky CSS magic, I was able to hide the message() statement. If I was evil, I could have changed this to a system, source, or any other command.</p>
<p>The CSS code simply sets the <code>message()</code> function to the background color, changes the font size and makes it un-selectable (see this <a rel="nofollow" href="http://lifepluslinux.blogspot.co.uk/2017/01/look-before-you-paste-from-website-to.html" target="_blank">post</a> for details). </p>
<p>So remember, be careful with your copy and pasting!</p>
<p><a rel="nofollow" href="https://www.jumpingrivers.com/?utm_source=blog&utm_campaign=June" target="_blank"><img data-orig-file="https://csgillespie.files.wordpress.com/2017/06/300_125.jpg?w=300&amp;h=150&amp;fit=300%2C150&amp;resize=300%2C150" data-orig-size="300,150" data-medium-file="https://csgillespie.files.wordpress.com/2017/06/300_125.jpg?w=300&amp;h=150&amp;fit=300%2C150&amp;resize=300%2C150?w=300" data-attachment-id="1224" data-image-meta="{" data-image-description="" src="https://csgillespie.files.wordpress.com/2017/06/300_125.jpg?w=300&h=150&fit=300%2C150&resize=300%2C150" data-permalink="https://csgillespie.wordpress.com/2017/06/07/uk-r-courses/300_125/" data-large-file="https://csgillespie.files.wordpress.com/2017/06/300_125.jpg?w=300&amp;h=150&amp;fit=300%2C150&amp;resize=300%2C150?w=300" alt="" data-image-title="300_125" sizes="(max-width: 300px) 100vw, 300px" data-comments-opened="1" class="wp-image-1224" data-recalc-dims="1"></a></p>
<p> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/csgillespie.wordpress.com/1206/" target="_blank"><img border="0" alt="" src="http://feeds.wordpress.com/1.0/comments/csgillespie.wordpress.com/1206/"></a> <img border="0" alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" data-recalc-dims="1"></p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://csgillespie.wordpress.com/2017/06/07/security-the-dangers-of-copying-and-pasting-r-code/"> R – Why?</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...

	<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/K4jseyC-btA" height="1"></a></div>