Flexdashboards : is the original dataframe used to create tables/graphs secure? - r

I am very sorry if this is a stupid question,
I was wondering… let’s say you have an HTML file created from R Markdown containing some graph. More specifically, this HTML document is a flexdashboard. Is it possible to obtain the original dataframe used to create the graph, using only this HTML file?
I don’t know if I managed to explain, but I am worried about the security of the original dataframe.
I suppose the real question is, how does Markdown knit the R chunks? Is it only the outcome of the code that is incorporated in the HTML document... or is it everything? I always thought that because knitr create a .md temporary file that contains the code and its outcomes that meant that it only contained the code and the outcomes and not the original dataframe used to make graphs, stats, tables, etc. But I may be completely wrong and I wish to know the truth.
If anybody has the answer (and maybe some tips in how to secure the flexdashboards), I would be very thankful. I hope I managed to explain my problem in a comprehensible way.

Related

How to continue project in new file in R

I have a large population survey dataset for a project and the first step is to make exclusions and have a final dataset for analyses. To organize my work, I must continue my work in a new file where I derive survey variables correctly. Is there a command used to continue work by saving all the previous data and code to the new file?
I don´t think I understand the problem you have. You can always create multiple .R files and split the code among them as you wish, and you can also arrange those files as you see fit in the file system (group them in the same folder with informative names and comments, etc...).
As for the data side of the problem, you can load your data into R, make any changes / filters needed, and then save it to another file with one of the billions of functions to write stuff to the disk: write.table() from base, fwrite() from data.table (which can be MUCH faster), etc...
I feel that my answer is way too obvious. When you say "project" you mean "something I have to get done" or the actual projects that you can create in rstudio. If it´s the first, then I think I have covered it. If it´s the second, I never got to use that feature so I am not going to be able to help :(
Maybe you can elaborate a bit more.

Repeatable Macros in R?

Is there any way in R to write a macro like one would in SAS? That is, I want to write a macro with some input variable (corresponding to a row in a dataset) so I can quickly make a plot of certain characteristics from said row. Any information regarding a package/method to do so would be greatly appreciated.
R will generate some very, very, very basic code for you. If you have RStudio installed, you can click File > Import Dataset > From ... point to your file and click 'Open'. R will automatically create the code to do the import. Again, this is very basic. You really need to know how to code to do anything useful.
You get out of it what you put into it, so spend some time learning this stuff, and inevitably you'll learn a ton. I've found that it's very helpful to read through people's questions that are posted here, and try to solve the problem yourself. You'll learn a lot that way and you'll see what the current trends are. Reading books is great, of course, but sometimes I feel like some authors are too academic, and in the real world, sometimes it's done differently than what you see in textbooks.

Using R's exams package for assignments: Is it possible to add question hints?

The exams package is a really fantastic tool for generating exams from R.
I am interested in the possibilities of using it for (programming) assignments. The main difference from an exam is that besides solutions I'd also like hints to be included in the PDF / HTML output file.
Typically I put the hints for (sub)-questions in a separate section at the end of the PDF assignment (using a separate Latex section), but this requires manual labour. These are for students to consult if they need help getting started on any particular exercise, and it avoids having them look at the solutions directly for hints on how to start.
An assignment might look like:
Question 1
Question 2 ...
Question 10
Hints to all questions
I'd be open to changing the exact format as long it is possible to look up hints without looking up the answer, and it remains optional to read the hints.
So in fact I am looking for an intermediate "hints" section between the between the "question" and "solution" section, which is present for some questions but not for all.
My questions: Is this already possible? If not, how could this be implemented using the exams package?
R/exams does not have dedicated/native support for this kind of assignment so it isn't available out of the box. So if you want to get this kind of processing you have to ensure it yourself using LaTeX for PDF or CSS for HTML.
In LaTeX I think it should be possible to do what you want using the newfloat and endfloat packages in the LaTeX template that you pass to exams2pdf(). Any LaTeX template needs to provide {question} and {solution} environments, e.g., the plain.tex template shipped with the package has
\newenvironment{question}{\item \textbf{Problem}\newline}{}
\newenvironment{solution}{\textbf{Solution}\newline}{}
with the exercises embedded as
\begin{enumerate}
%% \exinput{exercises}
\end{enumerate}
Now instead of the \newenvironment{solution}... you could use
\usepackage{newfloat,endfloat}
\DeclareFloatingEnvironment{hint}
\DeclareDelayedFloat{hint}{Hint}
\DeclareFloatingEnvironment{solution}
\DeclareDelayedFloat{solution}{Solution}
This defines two new floating environments {hint} and {solution} which are then declared delayed floats. And then you would need to customize these environments regarding the text displayed within the questions at the beginning and the listing at the end. I'm not sure if this can get you exactly what you want, though, but hopefully it is a useful place to start from.

Saving sequence tree from GraphViz

I'm new to TraMineR and sequence analysis in general. I am working on a project related to retention and recruitment of educational leaders and finding TraMineR to be very useful. This may be a simple thing (and somewhat unimportant), but I cannot seem to figure out how to name or direct the sequence tree created by GraphViz within the TraMinR package. Right now, my code is:
wardTree=as.seqtree(wardCluster,seqdata=retain.seq,diss=retain.dst,ncluster=15)
seqtreedisplay(wardTree,type="d",border=NA,showdepth=TRUE)
It produces a great graphic, but with a random file name that I cannot relocate if I accidentally close the graphic.
My main goal is to be able to uniquely name and save these graphs and pull into an R Markdown for the full project. To this point, the only thing I cannot pull in is the seqtree graphic.
Well, guess I figured it out! I didn't realize that the order in which filename command mattered...so...what seems to work out beautifully is:
wardTree=as.seqtree(wardCluster,seqdata=retain.seq,diss=retain.dst,ncluster=15)
seqtreedisplay(wardTree,type="d",border=NA,showtree=TRUE,showdepth=TRUE,filename="retaintree.png",imageformat="png")
And to incorporate the file in the Markdown i use the command
```
![](C:\Users\myname\Desktop\retaintree.png)
```{r fig.width=8.5, fig.height=11}
Hope this helps someone else along the way!

Self-documenting codes in R? [duplicate]

This question already has an answer here:
Automatic documentation of datasets
(1 answer)
Closed 8 years ago.
Is there any code self-documenting system for R?
I think writing documentation is a very important part of any statistical analysis. There are always important details in your code or the steps of data cleaning that are not reflected in the final analysis report. I wonder whether there is any efficient self-documenting system (or approach) in R that can help me documenting my codes including my comments o my codes with structure files explaining the structure of the datasets (or tables) used in my code?
Beyond using Sweave or knitr in R, is there any other way of doing that?
I'd suggest bundling up your code and data sets in an R package. There's a steep learning curve the first time you do it, but if you're at the point where you're asking, "how can I better manage this code documentation thing", you're likely ready to take the plunge.
Plus, doesn't the idea of typing ?myOwnFunction or ?myOwnDataset, and having the appropriate help file pop up (just as it does when you do ?mean or ?iris) sound appealing?
You might try writing your code as a Sweave or kntr file, which contains LaTeX text along with R code. This process produces a pdf of your text, including your code, and executes your code.
If you choose to organise your analysis as package, you can use roxygen2 for documentation of your code and data.

Resources