Issue I would like an object that gives me a date range for every month (or quarter) from 1990-01-01 to 2021-12-31, separated by a colon. So for example in the monthly case, the first object would be 1990-01-01:1990-01-31, the second
Continue readingTag: r
Find all date ranges for overlapping start and end dates in R
Issue I have a data frame that looks like this: w<-read.table(header=TRUE,text=” start.date end.date 2006-06-26 2006-07-24 2006-07-19 2006-08-16 2007-06-09 2007-07-07 2007-06-24 2007-07-22 2007-07-03 2007-07-31 2007-08-04 2007-09-01 2007-08-07 2007-09-04 2007-09-05 2007-10-03 2007-09-14 2007-10-12 2007-10-19 2007-11-16 2007-11-17 2007-12-15 2008-06-18 2008-07-16 2008-06-28 2008-07-26 2008-07-11
Continue readingLook for a string in a data frame and select the rows with R
Issue I have a table like this Column A Column B Column C Column D A x 1 k1 B k 2 k2 C z 3 k3 D y 4 k4 I would like to write a script which selects
Continue readingDetermine if the day of a month is in a date range, independent from its year
Issue Given I have time ranges with a start and an end date, I can easily determine if a specific date falls in this time range. How can we determine if a specific month/day combination lies in a time range,
Continue readingR (dplyr): find all rows in row-specific range
Issue I have a dataset where each row is identified by a hospitalization id. Each row contains information on the hospitalization id, hospital id where it took place as well as date of admission and date of discharge of the
Continue readingFind set of rows in row-specific range with restriction at different levels
Issue I have a dataset where each row is identified by a hospitalization id – physician id. Each row also contains information on the dates of admission and discharge and the hospital where it took place. A hospitalization may involve
Continue readingSelect Data – First entry + set time period (1 year) R
Issue I have a dataset on a group of individuals that was collected starting at different times for each individual. I need to subset the data from 1 year since their first entry, like so: myData[myDate >= "first entry" &
Continue readingCreate time range per group/location based on data set with movements
Issue I have a data set that contains movements of groups between different locations, which looks like this: library(data.table) df = data.table(Date = c(’01/01/2021′, ’06/01/2021′, ’09/01/2021′, ’10/01/2021′, ’20/01/2021′, ’24/01/2021′), Group = c(‘Group A’, ‘Group A’, ‘Group B’, ‘Group B’, ‘Group
Continue readingMerge two datasets based on date ranges. R
Issue My goal is to merge two datasets using date ranges. Dataset1 contains patients stays in a hospital overtime. Dataset2 contains room information overtime. My goal is to identify what type of room the stays were in my Dataset1. It
Continue readingHow to replace NAs by left_join, leave non NAs untouched
Issue I have a dataframe of locations with latitude and longitude in columns. df_places <- tibble( place_country = c("Melbourne, Australia", "Sydney, Australia", "Brisbane, Australia"), state = c("VIC", "NSW", "QLD"), temperature = c("Cold", "Cool", "Hot"), lon = c(41.23, NA, 43.55), lat
Continue readingR convert zipcode or lat/long to county
Issue I have a list of locations that contains a city, state, zip, latitude and longitude for each location. I separately have a list of economic indicators at the county level. I’ve played with the zipcode package, the ggmap package,
Continue readingHow to GeoCode a simple address using Data Science Toolbox
Issue I am fed up with Google’s geocoding, and decided to try an alternative. The Data Science Toolkit (http://www.datasciencetoolkit.org) allows you to Geocode unlimited number of addresses. R has an excellent package that serves as a wrapper for its functions
Continue readingR executable not working, but script works fine
Issue I have created a script that works fine when I run it from Rstudio. However, when I save it as “Rexec” and try to run it by double clicking, it only partially launches. I get a navigate gui pop-up
Continue readingError Handling and logging in R
Issue I have written a function in R to print any message both to log file and console. But if there is any unexpected error while running the code, then error is displayed only to console. Is there any way
Continue readingHow do I silence this specific message written to terminal/file (when calling an 'Rscript' via a bash script)
Issue I’m writing a bash script (to be called from the terminal — on a Linux system) that creates a log-file prior to initiating an ‘rscript’ using some simple user input. I’m however running into problems in controlling what messages
Continue readingR move columns to be rows of other columns
Issue I am converting a messy excel sheet into usable data. The basic structure is a repeating block of variables with similar items in rows. I want to move columns so they become rows of the first block of columns.
Continue readingR – Alter the order of a table
Issue I have this dataset structure(list(Data = structure(c(18750, 18750, 18750, 18750, 18751, 18751, 18751, 18753, 18753, 18753), class = "Date"), `Retorno D` = c(NA, NA, NA, NA, "211.52430499997001", "134.38776799989901", "361.888238000218", "180.13891600002501", "100.33839799999301", "211.93803400010799" ), `Retorno D-1` = c("99.984314000001206", "361.888238000218", "178.550884000026",
Continue readingR – Alter the order of a table
Issue I have this dataset structure(list(Data = structure(c(18750, 18750, 18750, 18750, 18751, 18751, 18751, 18753, 18753, 18753), class = "Date"), `Retorno D` = c(NA, NA, NA, NA, "211.52430499997001", "134.38776799989901", "361.888238000218", "180.13891600002501", "100.33839799999301", "211.93803400010799" ), `Retorno D-1` = c("99.984314000001206", "361.888238000218", "178.550884000026",
Continue readingParsing data in txt file to table (dataframe) in R
Issue I’m very new here and I’m also new in working with R programme. I would like to ask, please, how to parse out the data from a text file to the table in "Environment" section. Specifically, I have no
Continue readingAutomatically order a wide data.table: dcast columns in a specific order/setcolorder based on a pattern with numbers
Issue I have a DT like this: id = c(rep(1,10), rep(2, 5), rep(3,12)) th = c(rep(c(0,1),5), c(0, 1, 0, 1, 0), rep(c(1,0,1),4 )) drugs = c(rep(c("A","B","C","D","E"),2), c("A", "B", "B", "B", "A"), rep(c("C","D","c"),4 )) DT = data.table(id, th, drugs) DT id
Continue readingHow to move data from one column to another in R
Issue I am trying to move data from one column to another, due to the underlying forms being filled out incorrectly. In the form it asks for information on a household and asks for their age(AGE) and gender(SEX) for each
Continue readingSeparate a column without separators
Issue I have a dataset with a column that consists of a code and a number and I am trying to separate that column just to get the code. df <- data.frame(code=rep(c(‘2d01’, ‘2m04’, ‘3C06’, ‘CrD05’), each=10), pos=rep(c(3, 7,2,4), times=20)) df<-extract(df,code,into
Continue readingIs it possible to get R to identify countries in a dataframe?
Issue This is what my dataset currently looks like. I’m hoping to add a column with the country names that correspond with the ‘paragraph’ column, but I don’t even know how to start going about with that. Should I upload
Continue readingextract specefic colum based on character value in a row
Issue I have a data that contains character in the first row like this J K L M N O P A T F T F F F T B 14 15 10 2 3 4 78 C 10 47
Continue readingHow to create multiple new columns based on multiple conditions of other columns in R?
Issue I am trying to figure out how to create new columns based on other columns and insert another column’s value as observations in the newly created columns. Not sure how to clearly explain this in words so I will
Continue readingReplacing column with another data frame based on name matching
Issue Hi I am a bit new so I am not sure if I am doing this right, but I looked around on the overflow and couldn’t find a code or advice that worked with my code. I have a
Continue readingR group columns of return trips data
Issue I have data of train trips and the number of delayed or cancelled trains that I would like to make the sum. Start End Delayed Cancelled Paris Rome 1 0 Brussels Berlin 4 6 Berlin Brussels 6 2 Rome
Continue readingGoing from a dataframe with a factor column and numeric column to a dataframe with factor levels as columns and corresponding numeric values as rows
Issue If I take the following two-column dataframe, with one column being a factor and the other being a numeric vector: data <- data.frame(x=c("a","b","c","d","e","f","g","h"), y = c(1,2,3,3,2,1,5,6)) data$x <- as.factor(data$x) How can I turn it into a new dataframe data2
Continue readingTurn a column with repeating observations into a column for each observation in R
Issue My data currently looks like in the photo below. What I would like is a single column for all unique values of the "permno" variable with the following values of "ret_excess" as rows. So there would be a "10145"
Continue readingNew column based on rows of other dataframe
Issue I am wondering how I can create a new column and use the information of the corresponding row in a different dataset as input for that column. Suppose I have these two datasets: newDf <- data.frame(c("Juice 1", "Juice 2",
Continue readingNew column based on rows of other dataframe
Issue I am wondering how I can create a new column and use the information of the corresponding row in a different dataset as input for that column. Suppose I have these two datasets: newDf <- data.frame(c("Juice 1", "Juice 2",
Continue readingNew column based on rows of other dataframe
Issue I am wondering how I can create a new column and use the information of the corresponding row in a different dataset as input for that column. Suppose I have these two datasets: newDf <- data.frame(c("Juice 1", "Juice 2",
Continue readingNew column based on rows of other dataframe
Issue I am wondering how I can create a new column and use the information of the corresponding row in a different dataset as input for that column. Suppose I have these two datasets: newDf <- data.frame(c("Juice 1", "Juice 2",
Continue readingNew column based on rows of other dataframe
Issue I am wondering how I can create a new column and use the information of the corresponding row in a different dataset as input for that column. Suppose I have these two datasets: newDf <- data.frame(c("Juice 1", "Juice 2",
Continue readingNew column based on rows of other dataframe
Issue I am wondering how I can create a new column and use the information of the corresponding row in a different dataset as input for that column. Suppose I have these two datasets: newDf <- data.frame(c("Juice 1", "Juice 2",
Continue readingNew column based on rows of other dataframe
Issue I am wondering how I can create a new column and use the information of the corresponding row in a different dataset as input for that column. Suppose I have these two datasets: newDf <- data.frame(c("Juice 1", "Juice 2",
Continue readingNew column based on rows of other dataframe
Issue I am wondering how I can create a new column and use the information of the corresponding row in a different dataset as input for that column. Suppose I have these two datasets: newDf <- data.frame(c("Juice 1", "Juice 2",
Continue readingR- compare different columns of a data frame with different values
Issue I am currently working on microdata, using a survey called SHARE. I want to use a variable for education but the way it was coded makes it kind of hard. In the survey, households are asked what degree they
Continue readingCreate column based on multiple column and row criteria in R
Issue I am after some help with a bit of complex dataframe management/column creation. I have a data frame that looks something like this: dat <- data.frame(Target = sort(rep(c("1", "2", "3", "4"), times = 5)), targ1frames_x = c(0.42, 0.46, 0.50,
Continue readingAdding unique ID column associated to two groups R
Issue I have a data frame in this format: Group Observation a 1 a 2 a 3 b 4 b 5 c 6 c 7 c 8 I want to create a unique ID column which considers both group and
Continue readingOpening and reshaping xlsx files with nameless columns in r using a pattern
Issue I’m working with French electoral data but I’m having issues opening xlsx files to work on them in r. I was wondering if anyone had had the same problem and found a solution. The issue is that only the
Continue readingpivot_wider and unnest for a survey dataset questions needed to be reorganised
Issue I have this example data set that is consisted of 2 countries (Austria and France), 3 subsets (child, teenager, adult), 2 questions and 5 types of answers. This dataset looks as follows : country subset Questions Answers 1 Austria
Continue readingUnderstanding column handling function in R
Issue I’m trying to understand what this R function does: legacy_repair <- function(nms, prefix = "X", sep = "__") { if (length(nms) == 0) return(character()) # Returns a blank character variable? blank <- nms == "" # What does this
Continue readingHow can I extract characters from one column and add it into another existing column in R?
Issue I would like to extract information from one column and substitute it in another existing column. So this is what happened. I have a variable that identifies country_year, that I divided into two columns, country and year. So, just
Continue readingComparing certain column names in two dataframes
Issue I am looking for a way to compare two different data frame column names (only certain ranges of columns) and keeping only the names that have the same shared similarity of column names between the two data frames. (I
Continue readingCaret Training Issues in R
Issue I started playing with caret package recently and I’m trying to understand the training arguments. Below I used the Sonar dataset and created three imputs and the output. library(caret) library(mlbench) data(Sonar) set.seed(107) SonarImput1<-Sonar[,1:60] SonarImput2<-Sonar[,1:2] SonarImput3<-Sonar[,1] SonarOutCome<-Sonar[,61] mlp <- caret::train(SonarImput1,SonarOutCome,
Continue readingR: Check Variables in Training Data
Issue I’m using training data provided to me in an RData file, and a data frame I built myself with all the columns I thought there were in the training data. args = commandArgs(trailingOnly=TRUE) model = readRDS(args[1]) m = model[[1]]
Continue readingr caret estimate parameters on a subset fit to full data
Issue I have a dataset of 550k items that I split 500k for training and 50k for testing. During the training stage it is necessary to establish the ‘best’ combination of each algorithms’ parameter values. Rather than use the entire
Continue readingdplyr: select first half (or given proportion) of each group
Issue my need is simple: i have a data.frame with a grouping variable, like this: library(dplyr) proportion = 0.5; set.seed(1) df = data.frame(id=1:6, name=c(“a”, “a”, “b”), value=rnorm(6)) %>% arrange(name) I want to keep only the first half of each group
Continue readingIs it good practice to add a column specifying test set and train set?
Issue I found a tutorial a while back but cannot locate it again that created an extra column in both the train and the test set that specified true or false for being the training set. I have the code
Continue readingHow do I split my data set between training and testing sets while keeping the ratio of the target variable in both sets?
Issue I have a data set which I intend to split between a training set and testing set for a machine learning analysis using R. Assuming my data set (called MyDataset) has a ratio of Yes (60%) and No (40%)
Continue readingColumns not available for when training lasso model using caret
Issue I am getting an odd error Error in `[.data.frame`(data, , lvls[1]) : undefined columns selected message when I am using caret to train a glmnet model. I have used basically the same code and the same predictors for an
Continue readingError comes up, when my test set has data which my train data doesn't have?
Issue I have a dataset and have split it into train (80%) and test (20%) set. First step is setting up decision tree and then I predict using my test set. tree <- rpart(train$number ~ ., train, method = “class”)
Continue readingObservations with low frequency go all in train set and produce error in predict ()
Issue I have a dataset (~14410 rows) with observations including the country. I divide this set into train and test set and train my data using decision tree with the rpart() function. When it comes to predicting, sometimes I get
Continue readingerror using train command in caret package in r
Issue I am trying to make a glm model using caret in r using healthcare data from the CDC. However, whenever i try to train the model using the train() command in caret, i keep on getting the following error:
Continue readingHow to random search in a specified grid in caret package?
Issue I wonder it is possible to use random search in a predefined grid. For example, my grid has alpha and lambda for glmnet method. alpha is between 0 and 1, and lambda is between -10 to 10. I want
Continue readingHow to create a test and train dataset in R by specifying the range in the data set instead of using set.seed() function and probability?
Issue I am a noob at programming, sorry if this is a silly question. My supervisor doesn’t seem to trust set.seed() function in r as every number will yield a different output (with different test and train sets). Thus she
Continue readingPlot ROC curve for glm in R
Issue In my actual data, there are so many columns so I made the code using the position of the column. I want to plot ROC curve after logistic regression. To demonstrate what I want to do, I made a
Continue readingPlot ROC curve for glm in R
Issue In my actual data, there are so many columns so I made the code using the position of the column. I want to plot ROC curve after logistic regression. To demonstrate what I want to do, I made a
Continue readingString interpolation with R's glue on a vector, without calling it multiple times
Issue I’m looking to do string interpolation with R’s glue::glue() on a vector, without calling it multiple times. Example: df <- data.frame(x = 1:10) glue::glue("No. of Rows: {dim(df)[1]}, No. of Columns: {dim(df)[2]}") Would give as required: No. of Rows: 10,
Continue readingBetter string interpolation in R
Issue I need to build up long command lines in R and pass them to system(). I find it is very inconvenient to use paste0/paste function, or even sprintf function to build each command line. Is there a simpler way
Continue readingHighlighting bash code with knitr / rmarkdown
Issue I’m trying to generate an HTML report using RStudio, R Markdown and knitr. In the report I would like to display some bash code. I do not want to run the code but I would like it to be
Continue readingDifferences in R Markdown syntax highlighting for in-line code
Issue The following minimal R Markdown file minimal.Rmd produces different minimal.html output (via “Knit HTML” in RStudio) depending on my system. The first is the result on my Windows 8 machine. The second is the result on my Windows 7
Continue readingsyntax highlighting while rendering SQL using knitr
Issue knitr will execute SQL code using engine=’mysql’ but not highlight syntax: \documentclass{article} \begin{document} <<engine=’mysql’, engine.opts=”-h localhost”>>= SHOW DATABASES; @ \end{document} On the other hand using engine=’highlight’ will highlight the code but not execute it. \documentclass{article} \begin{document} <<engine=’highlight’, engine.opts=’-S sql
Continue readingIs rouge syntax highlighting meant to highlight non-base functions in R?
Issue I’m trying to understand the rouge syntax highlighter and in particular use it to highlight R code. Ultimately it’s for a website built with jekyll but I’ve been able to isolate my problems to just rouge (eg I use
Continue readingknitr syntax highlighting in .Rnw files (LaTeX)
Issue I am using .Rnw files to produce a report with LaTeX and knitr. My knitr_setup looks as follows: <<knitr_setup, echo=FALSE>>= library(knitr) opts_chunk$set(highlight = TRUE, cache = TRUE, eval = FALSE, size = “small”) options(width = 60) opts_knit$set(out.format = “latex”)
Continue readingSyntax highlighting rules and definitions
Issue Are there any standard syntax highlighting rules for R? If yes, where can they be found? Or does each editor, IDE, package (e.g., the highlight package) create their own rule set? Solution Each editor creates their own rule set.
Continue readingHighlight R Code Syntax in WordPress
Issue I would like to highlight R syntax in a wordpress blog, so that it looks similar as in RStudio. I found the wp-synthax-plugin, which is able to highlight R code as follows: However, the colors are in my opinion
Continue readingSweave syntax highlighting in output – revisit
Issue My question is the same as the one in the link Sweave syntax highlighting in output. I have followed the suggestion by daroczig https://tex.stackexchange.com/questions/5113/how-to-colorize-syntax-using-r-sweave, and created the following test.Rnw file: \documentclass{article} \RequirePackage{fancyvrb} \RequirePackage{listings} \SweaveOpts{keep.source=TRUE} <<SweaveListingsPreparations, results=tex, echo=FALSE, strip.white=false>>= require(SweaveListingUtils)
Continue readingHow to highlight all R function names with highlight.js?
Issue I want to extend highlight.js capabilities for R language so that (1) all function names that are followed by opening parenthesis ( and (2) all package names that are followed by :: and ::: operators would be highlighted (as
Continue readingCustom highlighting style in rmarkdown
Issue Is there a way to use a custom highlighting style in rmarkdown? Manual is a bit silent regarding that and the closest to that is to make a full blown custom css file for everything, that would however work
Continue readingHow to use variable R code in a Knitr chunk?
Issue I want to demonstrate use of a piece of R code. But I want the code to be variable itself. Example two tasks: Randomly select two variables from a data frame and add those columns. Randomly select a set
Continue readingHow to syntax highlight inline R code in R Markdown?
Issue This question is similar to consistent code html inline and in chunks with knitr. Instead of .Rhtml documents, I want to highlight inline R code in R Markdown documents, e.g., after `r “plot(cars, main = ‘A scatterplot.’)”` is compiled
Continue readingWhat does it mean when the variable name T is highlighted?
Issue I understand that R highlights specific text depending on its function, but what does it mean when the variable you are assigning is highlighted? And can it cause any problems? For example, T is highlighted automatically in: Solution It
Continue readingPrint Script with syntax highlighting R-Studio
Issue After finishing statistical analysis in R I always like to print out the script since it gives a good overview and one can adjust eventual errors. I like the syntax highlighting in R-Studio because it facilitates reading and fast
Continue readingStata syntax highlighting in Rmarkdown
Issue I am using Bookdown and Rmarkdown to compose a technical book for Stata users. I would like to include Stata highlighting syntax in the chunks of code, but I am not interested in actually executing Stata from Rstudio. I
Continue readingOverride bad/wrong values in a main table with NA or null values listed on another lookup table in R
Issue The main table is large. Has certain undesired values that I want to override. I am writing into a lookup table the keys and new_value (NA) to override. Both have 2 keys (session_id and datetime), not one unique. Other
Continue readingSplit string of concatenated digits into a numeric vector of individual values
Issue Suppose I have a long string of concatenated digits, 0 and 1: "1010101010101010100011011" I would like to split the individual values and separate them by a , like so "1,0,1,0,1,0,1,1,…". Then transform into a numeric vector like this: c(1,0,1,0,1,…)
Continue readingR Shiny unable to start png device after running a few hours
Issue I have had various R Shiny applications running successfully (some for over a year) on a Windows PC serving a local intranet network. In the last couple of weeks, the applications started to fail loading plots with the error:
Continue readingHow to get the difference of 2 images to visually compare complex-data visualizations by substracting ggplot's images
Issue I am working with two giant datasets taken under similar circumstances and produces very similar, but non-equal results. I need to visually highlight differences between both. I previously built a heatmap helper function that is able to draw each
Continue readingHow do I permanently change a vector in R?
Issue I am trying to simulate a tournament where, in each round, two randomly selected players out of thirteen play, and their Elo rating (a measure of their relative skill level) gets updated. Each player has a true underlying skill
Continue readingIs there a way to change the index on kmeans()$cluster?
Issue I am using kmeans() to create groups based on a score. The goal is to assign star ratings, so that the individuals with the highest scores get four stars, and the individuals with the lowest scores get 1 star.
Continue readingGlicko-2 implementation in R, where to find?
Issue I am looking for an R implemention of the excellent Glicko-2 algorithm of Mark Glickman. Thusfar I found this one. Although this is a very nice piece of code I am particularly looking for a code that is able
Continue readingIs there a way to *output* star rating in R Shiny?
Issue Dears, In my app, users rate some stuff. I want to output 5-star ratings based on their ratings just like the ones in IMDB. There are fractions in my numbers, and I want the stars to accommodate them. I
Continue readingError in for loop in ELO rating algorithm
Issue I’m trying to run the ELO rating code from here https://github.com/xsankar/hairy-octo-hipster/blob/master/ELO-538.R The dataset I’m using is here https://www.mediafire.com/file/0a5v393ki775vw9/sport2.xlsx/file The code I’m running is slightly modificated, I’m working with only 17 weeks instead of 22 as in the original code,
Continue readingModel fitting functions and environemnts
Issue Here is a kind of minimal example for a problem I stumbled upon: mylm <- function(formula,data,subset=NULL){ mysubset <- subset # some other clever manipulation lm(formula,data,mysubset) } mydata <- data.frame(x=rnorm(10),y=rnorm(10)) mylm(y~x,mydata) # this fails! The reason why the last line
Continue readingHow can a non-imported method in a not-attached package be found by calls to functions not having it in their namespace?
Issue An R namespace acts as the immediate environment for all functions in its associated package. In other words, when function bar() from package foo calls another function, the R evaluator first searches for the other function in <environment: namespace:foo>,
Continue readingAny way to access function installed by makeActiveBinding?
Issue The title basically says it all. If I do this … makeActiveBinding(“x”, function() runif(2), .GlobalEnv) x # [1] 0.7332872 0.4707796 x # [1] 0.5500310 0.5013099 … is there then any way for me to examine x to learn what
Continue readingError in eval(expr, envir, enclos) : object * not found when wrapping qplot()
Issue I don’t understand why my oh-so-minimal wrapper function produces the subject error. The below should reproduce it. My goal is to do a bunch of plots from data in a single dataframe, each of which lives in a new
Continue readingR: Scoping rules are getting me into murky waters
Issue Any help with this problem I’m having would be greatly appreciated. I am a moderately advanced R programmer, but so far all my solutions have failed me. I start with the logic behind what I am trying to do,
Continue readingScoping issue with using function to add rows to data frame?
Issue I wonder if this might be a scoping problem. I am new to R and am trying to use a function on a series of columns and outputing the results to a new data frame. The function should add
Continue readingEnvironments in R Shiny
Issue At http://shiny.rstudio.com/articles/scoping.html the rules for scoping in shiny are well explained. There are 3 environments or levels nested inside each other: objects available within a function, within a session and within all sessions. Using <- will change the object
Continue readingCan you enable an R function to see the values of its own formals on evaluation?
Issue In the R, language, suppose I have a function ff(jj, kk, mm). I would like the calling function (or calling human being in an interactive session) to be able to make mm depend in arbitrary ways on jj and
Continue readingupdate function in R and variables access
Issue I need to update a model formula inside a function. This is an example: A <- runif(n = 200) # generate some data B <- runif(n = 200) P <- 1/(1+exp(.5-A)) # generate event probability outcome <- runif(n =
Continue readingRcpp scoping of free variables
Issue Say that I have a C++ function dosomething(z) that has a single input variable z, but also a “free” variable located within it (say y). I want to be able to design the scoping so that when I run
Continue readingFunction flow: why does this function return 20
Issue Suppose I have a function called l: l <- function(x) x + 1 then define another function, m, but within m, redefine l: m <- function() { l <- function(x) x*2 l(10) } m() Why does m return x*2,
Continue readingR shiny object scoping
Issue I’m trying to access an object(a<-get(obj1,envir=parent.environment())) residing in the calling environment from the called environment myf and I can’t get it working. Error I’m getting is Object obj1 not found. I tried parent.frame()also. Any ideas? library(shiny) shinyApp( ui =
Continue readingScoping-related (?): anova() on list of created mixed-effects models
Issue In a project where I’m performing mixed-effects modelling using lme, I’m trying to compare models with different correlation structures and equal fixed parts. As I’ll be building a lot of these models (for different dependent variables), I tried to
Continue readingSetting attributes of an object that was created in a function
Issue (The title is probably quite bad, but I’m not sure how to describe it better) I have a (rich) object that is created via a function. This object has multiple attributes. One attribute is a function, that should (among
Continue readingAvoiding repeated creation of objects in RMarkdown document through if statement
Issue I’m working on a RMarkdown document that uses objects that take a long time to create and transform. The syntax is similar to this: — title: “Example” author: “Test” date: “October 29, 2015” output: pdf_document — Example “`{r} test_exc
Continue reading