Answered step by step
Verified Expert Solution
Link Copied!

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.
(1 min /0 pts) After installing R and then R Studio, launch R Studio and create an R Project titled "CS5200.BuildFileDB.LastName" where LastName is your last name.
(1 min /0 pts) In the R Project, create an R program (script) titled "FileDB-LastName.R" where LastName is your last name.
(5 min /5 pts) R programs run as a script starting with the first line. Adopting the mechanism from C/C++, 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 C/C++, 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 one-pass execution model and is not compiled.
Only global variables can be declared outside of main().
The code fragment below shows this approach:
globalVar <-0
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 configDB(root, 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, e.g., 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 (i.e.,,"") or under the provided path within the project folder.
Write a function called getExtension(fileName) that returns the extension of the file name, e.g., 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, e.g., JPG or JAVA or PDF.
Write a function called getFileStem(fileName) that returns the stem of the file name, e.g., if the fileName argument has the value "CampusAtNight.jpg it should return the string "CampusAtNight".
Write a function called genObjPath(root, tag) that returns the correctly generated path to a file type folder, e.g., if the extension of the file is .jpg it would return "docDB/JPG". 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 storeObjs(folder, 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 storeObjs(folder, 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 clearDB(root) 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago

Question

=+1. How is economics like a science?

Answered: 1 week ago