When trying to delete a directory, one can encounter some unexpected problems. The function for carrying out this operation is
unlink, which accepts the director name as its first argument; other arguments are
recursive (a logical vector or length 1 indicating whether we want to delete subdirectories, and
force, also logical, which tries to override file permissions in most cases. It returns
0 when successful and
1 when not.
But there is a gotcha to using the function. First let’s list the contents of the HOME directory
 "3D Objects"
 "New folder"
 "Saved Games"
Let’s say we want to delete the ‘New folder’ directory
> (unlink('New folder/', recursive = TRUE, force = TRUE))
Even when you study the help file, the source of this failure is not apparent.
Well, it turns out that the function does not recognize the trailing slash that indicates that we are dealing with a directory. This is always added when you use tab completion for the directory name.
So, when we type
# Remove trailing slash in directory name
> (unlink('New folder', recursive = TRUE, force = TRUE))
The function succeeds, as evidenced by listing the directory contents
 "3D Objects"
 "Saved Games"
Watch out for this!
Adventures with R
I’ve been learning a lot these days. It’s been coming fast and heavy and I have not been able to document much of it. One of the areas I kind of focused on was Environments. I’ve glanced at (but not finished) the chapter Hadley Wickham wrote in his book ‘Advanced R’. One thing that stood out clearly was that environments are data structures just like any other in the language. I will pause there for now.
What I rushed out to post is something I just saw in a post in R Bloggers. The main gist was about loading .RData files safely and this is one area where environments can be put to good use.
Rather than loading the objects from that file into the Workspace (or global environment), just create a new environment with
new.env() and load the saved objects into into it by passing it as…
View original post 86 more words
In the introduction to his book R packages, Hadley Wickham provides a neat function for making sure that everything is set for writing your own R extensions, by simply running the
devtools::has_devel(), which, if all goes well, should evaluate to
This did not work out for me and I had to fix this problem on 2 different occasions so I felt I need to share this info in case there are others also stumped by this hurdle.
The fix I found – after a full sweaty day – was in this conversation on GitHub and I would like to break it down very quickly:
- Make sure you have installed Rtools from CRAN
- Make sure that Rtools/bin as well as Rtools/MinGW/x64/ are added to your system PATH (if you don’t know how, click here)
- In addition, it is recommended that you install LATEX (the link is also found on the Rtools page mentioned on No. 1)
- Run the following lines of code
install_github("hadley/devtools") # to get the latest 'pre-CRAN' package updates
has_devel() # output should be TRUE
Like I said, I had this problem on 2 different machines (Windows 7 and 10) and the same fix worked on both of them.
Well, I just have to share this with whosoever is desperately looking for a solution to this problem and happens to stumble across this post.
It’s not easy being a newbie in any thing, and computing is no exception.
I have written a small program that I will be using for my work in the office and which would also benefit a few staffers. I wrote it in C++ and compiled it using Visual Studio. However, I couldn’t find the executable file (*.exe) anywhere on my computer!
I went over to the MSDN site, as well as StackOverflow, looking for a solution but there was none in sight. To make matters worse, I discovered that MANY beginner programmers were facing the same issue.
Then I found this video on YouTube – and voilá! – problem solved. The answer to my question is ridiculously straightforward; indeed, ignorance is very costly.
If you’re in a bind like I was, I hope this works for you the way it did for me!