I am trying to get my head around the dir.create() function to create nested folders "folder2" and "folder3".
The solution would be:
dir.create(file.path("folder2", "folder3"), recursive = TRUE)
Edit: explanation of ?dir.create
is
recursive logical. Should elements of the path other than the last be created? If true, like the Unix command mkdir -p.
What is the purpose of the recursive attribute?
Picking up from 'mkdir -p' in your question, and explanation here:
If your 'folder2' included parent folders, these will need to be created first, else the create function would not be able to create the final file at the end of the path (there wouldn't be anywhere to put it, as the full path doesn't exist yet).
Lets say 'folder2' was 'a/b/c/'. To create folder 'c', you first need to create folder 'b'. But for 'b' you first need 'a'. So all the parent folders need to be created before the final child folder (or file).
'recursion' refers to 'stepwise repeating again and again'. [make 'a' then 'b' and finally 'c']