Below is a step-by-step guide on how to run the R script.
#set working directory to $HOME/Desktop/proof-of-concept
#setwd("/Users/sophieavard/Desktop/proof-of-concept")
You need to set your working directory to the proof-of-concept folder (which should be saved on your Desktop).
getwd()
[1] "/Users/sophieavard/Desktop/Sophie-Avard-Proof-of-Concept/proof-of-concept"
install.packages('plyr', repos = "http://cran.us.r-project.org")
Installing package into ‘/Users/sophieavard/Desktop/Sophie-Avard-Proof-of-Concept/proof-of-concept/renv/library/R-3.6/x86_64-apple-darwin15.6.0’
(as ‘lib’ is unspecified)
cannot open URL 'http://cran.cnr.berkeley.edu/bin/macosx/el-capitan/contrib/3.6/PACKAGES.rds': HTTP status was '404 Not Found'trying URL 'http://cran.us.r-project.org/bin/macosx/el-capitan/contrib/3.6/plyr_1.8.4.tgz'
Content type 'application/x-gzip' length 965992 bytes (943 KB)
==================================================
downloaded 943 KB
The downloaded binary packages are in
/var/folders/dc/ynp6mgyd67s_7ydkkh8lrylr0000gn/T//RtmpUePfcE/downloaded_packages
install.packages("pdftools")
The following package(s) are missing their DESCRIPTION files:
packrat 2
pdftools 10
pdftools 11
pdftools 12
pdftools 13
pdftools 14
pdftools 15
pdftools 16
pdftools 2
pdftools 3
pdftools 4
pdftools 5
pdftools 6
pdftools 7
pdftools 8
pdftools 9
Consider removing or re-installing these packages.
Library: "~/Desktop/Sophie-Avard-Proof-of-Concept/proof-of-concept/renv/library/R-3.6/x86_64-apple-darwin15.6.0"
Installing pdftools [2.2] ...
OK (linked cache)
library(pdftools)
install.packages("devtools")
The following package(s) are missing their DESCRIPTION files:
packrat 2
pdftools 10
pdftools 11
pdftools 12
pdftools 13
pdftools 14
pdftools 15
pdftools 16
pdftools 2
pdftools 3
pdftools 4
pdftools 5
pdftools 6
pdftools 7
pdftools 8
pdftools 9
Consider removing or re-installing these packages.
Library: "~/Desktop/Sophie-Avard-Proof-of-Concept/proof-of-concept/renv/library/R-3.6/x86_64-apple-darwin15.6.0"
Installing devtools [2.2.1] ...
OK (linked cache)
devtools::install_github("ropenscilabs/qcoder")
Skipping install of 'qcoder' from a github remote, the SHA1 (96e424bb) has not changed since last install.
Use `force = TRUE` to force installation
library(qcoder)
Install all of the packages needed for this proof of concept. The pdftools packages allows users to convert pdfs to text files. The devtools package makes package development easier as it provides R functions that simplify common tasks. The last two lines of the script installs the textual analysis package ‘qcoder’.
file.names <- dir(path="pdfs", pattern =".pdf", full.names=TRUE)
This creates a variable called file.names that builds a path to the pdfs that need to be converted into txt files. ‘Path=’ is the directory containing the files and ‘pattern=’ is the pattern of the files - in this case the files all end in “.pdf”. If full.names=TRUE, the directory path is prepended to the file names to give a relative file path, if FALSE, the file names are returned.
for (file in file.names) {
text <- pdf_text(file)
output.file <- gsub("pdf", "txt",file)
print(output.file)
print(file)
write(text, output.file)
}
[1] "txts/Fabian_2018.txt"
[1] "pdfs/Fabian_2018.pdf"
[1] "txts/Robinson_2018.txt"
[1] "pdfs/Robinson_2018.pdf"
For loops are used to repeat a specific block of code. In this for loop, we are repeating the sequence of text <- pdf_txt(file) for each file within file.names (that is, within the pdfs directory).
The gsub function finds all matches of a string and replaces it with the new string. That is, in file all occurrences of “pdf” will be replaced with “txt” - this will create a variable called output.files.
The print() function is an argument that prints the string on the console
The write() function writes the data to a file. That is, ‘text’ is the data to be written out and ‘output.file’ is the string naming the file to write to (in this case, “txt”)
#create_qcoder_project("qcoder-analysis-project")
import_project_data(project = "qcoder-analysis-project")
The ‘create’ function is used when users want to create an empty qcoder analysis. The ‘import’ function is used when users when to open an existing analysis. For the purposes of this PoC only the ‘import’ function will be used.
‘Project=’ is the name of the qcoder analysis.
project_name = "qcoder-analysis-project"
file_name <- "Fabian_2018.txt"
docs_df_path <-"qcoder-analysis-project/data_frames/qcoder_documents_qcoder-analysis-project.rds"
codes_df_path <- "qcoder-analysis-project/data_frames/qcoder_codes_qcoder-analysis-project.rds"
file_path <- "qcoder-analysis-project/documents"
dir("qcoder-analysis-project/documents")
[1] "Fabian_2018.txt" "Robinson_2018.txt"
file_name builds a path to the data docs_df_path builds a path to the directory that holds the data codes_df_path builds a path to the codes file_path builds a path to the directory holding the files
rawPath <- "~/Desktop/Sophie-Avard-Proof-of-Concept/proof-of-concept/txts"
datafiles <- dir(rawPath, "*.txt", ignore.case = TRUE, all.files = TRUE)
file.copy(file.path(rawPath, datafiles), file_path, overwrite = TRUE)
[1] TRUE TRUE
rawPath builds a path to the directory holding the txt files - make sure you change this to the path of the ‘proof-of-concept’ folder (located on your Desktop) datafiles builds a path to the files containing “.txt” within the rawPath ignore.case = TRUE constructs a case insensitive pattern
The ‘file.copy’ function creates a copy of of the datafiles within the rawPath and places them within the file_path (“qcoder-analysis-project/documents”).
new_dataframe <- readRDS(docs_df_path)
This proves that the data is ‘in’ the system as it writes a single R object (docs_df_path) to a file, and restores the object as new_dataframe.
read_code_data(project_name = project_name)
This reads the csv file containing the codes within the project
codes_dataframe <- readRDS(codes_df_path)
This loads the codes into R
qcode(use_wd=TRUE)
Loading required package: shiny
Registered S3 method overwritten by 'dplyr':
method from
print.rowwise_df
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
Attaching package: ‘rlang’
The following object is masked from ‘package:magrittr’:
set_names
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
Attaching package: ‘DT’
The following objects are masked from ‘package:shiny’:
dataTableOutput, renderDataTable
Watch shinyjs tutorial videos and read the full documentation:
https://deanattali.com/shinyjs
Attaching package: ‘shinyjs’
The following object is masked from ‘package:shiny’:
runExample
The following objects are masked from ‘package:methods’:
removeClass, show
here() starts at /Users/sophieavard/Library/Application Support/renv/cache/v4/R-3.6/x86_64-apple-darwin15.6.0/qcoder/0.1.0/7cc7c1d931e831a340220be996967cd2/qcoder
NA
This connects the Shiny app to the working directory and then opens it.