Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Tasks The tasks below assume that you have installed R and R Studio or created an account on rstudio.cloudLinks to an external site.. The tasks
Tasks
The tasks below assume that you have installed R and R Studio or created an account on rstudio.cloudLinks to an external site.. The tasks below guide you through the process of creating a document store that uses folders as a means to organize data by file type. The "records" that are stored are files. Files have extensions that indicate the type of file and its contents. For example, a file with the extension jpg or jpeg is an image stored using the JPEG file format.
min pts After installing R and then R Studio, launch R Studio and create an R Project titled CSBuildFileDB.LastName" where LastName is your last name.
min pts In the R Project, create an R program script titled "FileDBLastName.R where LastName is your last name.
min pts R programs run as a script starting with the first line. Adopting the mechanism from CC make the first line of code of the R program a call to the function main and the second line a call to quit which works like the function exit in CC although when running the script within R Studio, quit may cause an error, so you may wish to comment it out during development.
Next, write a function called main before the call to main that will eventually call all other functions we will build below. All of your "testing code" will eventually be in main
We will not use any kind of unit testing packages. All code must be in the function main or some other function. All functions must be defined before they are first used as R uses a onepass execution model and is not compiled.
Only global variables can be declared outside of main
The code fragment below shows this approach:
globalVar
main function
# all program code starts here
print Hello World"
#########################################################
main
Add a global variable before main called rootDir that has the value "docDB".
Write a function called configDBroot path that sets up all folders and the database related structure. For now that is just the folder in which all file type folders will be stored, eg assuming that the value "docDB" is passed for root, the function creates the folder "docDB" in the project folder if the path argument is empty ie or under the provided path within the project folder.
Write a function called getExtensionfileName that returns the extension of the file name, eg if the fileName argument has the value "CampusAtNight.png it should return PNG The object type garnered from the extension must be all capital case, eg JPG or JAVA or PDF
Write a function called getFileStemfileName that returns the stem of the file name, eg if the fileName argument has the value "CampusAtNight.jpg it should return the string "CampusAtNight".
Write a function called genObjPathroot tag that returns the correctly generated path to a file type folder, eg if the extension of the file is jpg it would return "docDBJPG Note the stripped in the path. For jpeg it should also return JPG while for doc and docx it should return DOC. You can assume that the extension is everything after the last in the file name. Assume that any other dots periods prior to the last one are part of the file name.
Write a function called storeObjsfolder root that copies all files in the folder argument to their correct folders underneath the root folder. Create folders for the extensions as needed. Any file without an extension should be ignored and not copied. Ignore any subfolders. The folder containing the files to be copied cannot be in the folder specified in root.
Leverage all of the functions developed previously when building this function. Decompose your code into functions and use proper programming and software engineering practices.
For example, if the folder specified in the folder argument contains the files "foobar.jpg and "barfoo.pdf then the functions should store foobar.jpg in the folder JPG and barfoo.pdf in the folder PDF If the folder do not yet exist, they should be created.
Modify the function storeObjsfolder root created above so that it takes a third argument verbose that is a boolean. If the argument is true, modify the code for the function so that it prints a message for every file that is copied. The message should have the form: "Copying CampusAtNight to folder TIFF". In general, it should print the name of the file being copied without its extension and the folder to which it is copied based on the extension.
Write a function called clearDBroot that removes all folders and files in the folder specified by root but not the folder for root itself. This function is used to "reinitialize" the database to a "blank"state.
Add testing code to main to demonstrate that your functions are working.
Verify that your code is properly structured and documented and follows generally accepted programming practices.Write as much documentation as you need to
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started