Re: [R] error "variable names are limited to 256 bytes" when sourcing code
Brian Frizzelle wrote: I've written a function that takes some input data output from a simulation model and creates some graphs. It's not very complicated code, and it works perfectly fine if I just run the code as is. But I have converted it into a function so we call it externally, and when I try to source the code to test the function, I get the error message "variable names are limited to 256 bytes". I've tried searching online for a solution to this, but everything I have come across deals with this error in relation to input data, not a function. The code is 389 lines long, so I'd rather not paste it here and clog up inboxes. If you have an idea as to why this is happening and would like to see the code, please email me and I will send it to you. Current versions of R will tell you which line contained the error. Can't you find and post just that one line? If you aren't seeing an error report, you could divide and conquer: edit blocks out of your file until you can figure out which lines matter. My guess would be something involving backticks (i.e. things like `x`); R will see the first one, and collect characters until the next one as a single identifier. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error "variable names are limited to 256 bytes" when sourcing code
Well, that's embarrassing. Thank you for finding that. -- View this message in context: http://r.789695.n4.nabble.com/error-variable-names-are-limited-to-256-bytes-when-sourcing-code-tp2231800p2232244.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error "variable names are limited to 256 bytes" when sourcing code
I was about to say the same. loading the code line per line gave the error a few lines after that one. Which explains... Cheers Joris On Wed, May 26, 2010 at 9:27 PM, Erik Iverson wrote: > Is the '`' character supposed to be there before the ## Add error bars > comment? > > If that is the problem, let it be a good lessonto use an editor with > syntax highlighting. :) > > > > > Brian Frizzelle wrote: > >> All, >> >> I think there may be some misunderstanding about my problem. In my code, >> which is written as an R function, all of my variable names are short. I >> get >> that error when I try to source the function so I can call it. I just do >> not >> know why I'm getting the error, especially since I have written other very >> similar functions that all work. >> >> So I have chosen to post the code below. I welcome any ideas about where >> in >> this code the error is occurring. >> >> ## >> ### SCRIPT: graph_hh_wealth_function.R >> ### DATE: April 22, 2010 >> ### AUTHOR: Brian Frizzelle >> ### ### This function draws two line >> graphs of household-level wealth from a >> variable ### in a dataset output from an agent-based model run. >> ### >> ### The two graphs are: >> ### 1) a line graph showing change in Wealth over time for each >> individual >> ### household >> ### 2)a line graph of summary statistics of Wealth for the >> households >> (min, >> ### max, mean, and error bars) >> ### >> ### Required Arguments: >> ### * inpath -The path to the directory containing the >> village-level >> statistics >> ### file >> ### NOTE: Use the UNIX forward slash (/) convention when >> entering the path >> ### and do not include a slash at the end of the path. >> ### OK: "D:/data" >> ### Not OK: "D:\data" >> ### Not OK: "D:/data/" >> ### * infile - The name of the village-level statistics file >> ### * outpath - The path to the directory where you want the >> output graphics >> to >> ### be saved >> ### * outpref - The prefix that you want for the output PNG graphics >> files >> ### NOTE: Do not include underscores (_) or spaces in the >> output prefix. >> ### Instead, please use dashes (-). Your prefix will >> be separated >> ### from the remainder of the file names by a dash. >> ### >> ### Optional Arguments: >> ### * log.plot - Logical. Default is FALSE. >> ### If TRUE, then the individual household wealth >> graph is plotted >> ### with a logarithmic Y-axis. >> ### If FALSE, then the individual household wealth >> graph is plotted >> ### with a standard Y-axis. >> ### * err.bar - Logical. Default is TRUE. >> ### If TRUE, then error bars of 1 standard deviation >> will be drawn >> ### around the mean. >> ### If FALSE, then no error bars will be drawn. >> ### * n.quantiles - Integer. Value between 3 and 10. Default is 0, >> meaning >> no >> ### quantile lines will be drawn. >> ### This is the number of bins into which you would >> like the variable >> ### separated. One line for each will be drawn, with >> the exception of >> ### the min and max, which are already drawn. >> ## >> >> graph.hh.wealth <- function(inpath, infile, outpath, outpref, >> log.plot=FALSE, err.bar=TRUE, >> n.quantiles=0) >> >> { >> >>##* >>## Set the path and name of the input file >>## - The 'paste' command concatenates the two >>## - The 'skiplines' var sets the number of lines >>## to skip when reading in the dataset. >>##* >>if (substr(inpath, nchar(inpath), nchar(inpath)) == "/") >>inpath <- substr(inpath, 0, nchar(inpath)-1) >>if (substr(outpath, nchar(outpath), nchar(outpath)) == "/") >>outpath <- substr(outpath, 0, nchar(outpath)-1) >>pathfile <- paste(inpath, infile, sep="/") >>skiplines <- 1 >> >>##* >>## Set the names of the output file graphics >>##* >>fnout.wlth <- "hhwealth.png" >>fnout.wlthss <- "hhwealth-sumstats.png" >>output.png.wlth <- paste(outpath, "/", outpref, fnout.wlth, sep="") >>output.png.wlthss <- paste(outpath, "/", outpref, fnout.wlthss, >> sep="")
Re: [R] error "variable names are limited to 256 bytes" when sourcing code
Is the '`' character supposed to be there before the ## Add error bars comment? If that is the problem, let it be a good lessonto use an editor with syntax highlighting. :) Brian Frizzelle wrote: All, I think there may be some misunderstanding about my problem. In my code, which is written as an R function, all of my variable names are short. I get that error when I try to source the function so I can call it. I just do not know why I'm getting the error, especially since I have written other very similar functions that all work. So I have chosen to post the code below. I welcome any ideas about where in this code the error is occurring. ## ### SCRIPT: graph_hh_wealth_function.R ### DATE: April 22, 2010 ### AUTHOR: Brian Frizzelle ### ### This function draws two line graphs of household-level wealth from a variable ### in a dataset output from an agent-based model run. ### ### The two graphs are: ### 1) a line graph showing change in Wealth over time for each individual ### household ### 2)a line graph of summary statistics of Wealth for the households (min, ### max, mean, and error bars) ### ### Required Arguments: ### * inpath -The path to the directory containing the village-level statistics ### file ### NOTE: Use the UNIX forward slash (/) convention when entering the path ### and do not include a slash at the end of the path. ### OK: "D:/data" ### Not OK: "D:\data" ### Not OK: "D:/data/" ### * infile - The name of the village-level statistics file ### * outpath - The path to the directory where you want the output graphics to ### be saved ### * outpref - The prefix that you want for the output PNG graphics files ### NOTE: Do not include underscores (_) or spaces in the output prefix. ### Instead, please use dashes (-). Your prefix will be separated ### from the remainder of the file names by a dash. ### ### Optional Arguments: ### * log.plot - Logical. Default is FALSE. ### If TRUE, then the individual household wealth graph is plotted ### with a logarithmic Y-axis. ### If FALSE, then the individual household wealth graph is plotted ### with a standard Y-axis. ### * err.bar - Logical. Default is TRUE. ### If TRUE, then error bars of 1 standard deviation will be drawn ### around the mean. ### If FALSE, then no error bars will be drawn. ### * n.quantiles - Integer. Value between 3 and 10. Default is 0, meaning no ### quantile lines will be drawn. ### This is the number of bins into which you would like the variable ### separated. One line for each will be drawn, with the exception of ### the min and max, which are already drawn. ## graph.hh.wealth <- function(inpath, infile, outpath, outpref, log.plot=FALSE, err.bar=TRUE, n.quantiles=0) { ##* ## Set the path and name of the input file ## - The 'paste' command concatenates the two ## - The 'skiplines' var sets the number of lines ## to skip when reading in the dataset. ##* if (substr(inpath, nchar(inpath), nchar(inpath)) == "/") inpath <- substr(inpath, 0, nchar(inpath)-1) if (substr(outpath, nchar(outpath), nchar(outpath)) == "/") outpath <- substr(outpath, 0, nchar(outpath)-1) pathfile <- paste(inpath, infile, sep="/") skiplines <- 1 ##* ## Set the names of the output file graphics ##* fnout.wlth <- "hhwealth.png" fnout.wlthss <- "hhwealth-sumstats.png" output.png.wlth <- paste(outpath, "/", outpref, fnout.wlth, sep="") output.png.wlthss <- paste(outpath, "/", outpref, fnout.wlthss, sep="") ##* ## Read in the household-level output dataset ##* hhstats <- read.delim(file=pathfile, header=TRUE, sep ="\t", dec=".", skip=skiplines) ##* ## Get some information from the household-level ## dataset for use in plotting. ## - the village number ## - a vector of the unique HH IDs
Re: [R] error "variable names are limited to 256 bytes" when sourcing code
All, I think there may be some misunderstanding about my problem. In my code, which is written as an R function, all of my variable names are short. I get that error when I try to source the function so I can call it. I just do not know why I'm getting the error, especially since I have written other very similar functions that all work. So I have chosen to post the code below. I welcome any ideas about where in this code the error is occurring. ## ### SCRIPT: graph_hh_wealth_function.R ### DATE: April 22, 2010 ### AUTHOR: Brian Frizzelle ### ### This function draws two line graphs of household-level wealth from a variable ### in a dataset output from an agent-based model run. ### ### The two graphs are: ### 1) a line graph showing change in Wealth over time for each individual ### household ### 2)a line graph of summary statistics of Wealth for the households (min, ### max, mean, and error bars) ### ### Required Arguments: ### * inpath -The path to the directory containing the village-level statistics ### file ### NOTE: Use the UNIX forward slash (/) convention when entering the path ### and do not include a slash at the end of the path. ### OK: "D:/data" ### Not OK: "D:\data" ### Not OK: "D:/data/" ### * infile - The name of the village-level statistics file ### * outpath - The path to the directory where you want the output graphics to ### be saved ### * outpref - The prefix that you want for the output PNG graphics files ### NOTE: Do not include underscores (_) or spaces in the output prefix. ### Instead, please use dashes (-). Your prefix will be separated ### from the remainder of the file names by a dash. ### ### Optional Arguments: ### * log.plot - Logical. Default is FALSE. ### If TRUE, then the individual household wealth graph is plotted ### with a logarithmic Y-axis. ### If FALSE, then the individual household wealth graph is plotted ### with a standard Y-axis. ### * err.bar - Logical. Default is TRUE. ### If TRUE, then error bars of 1 standard deviation will be drawn ### around the mean. ### If FALSE, then no error bars will be drawn. ### * n.quantiles - Integer. Value between 3 and 10. Default is 0, meaning no ### quantile lines will be drawn. ### This is the number of bins into which you would like the variable ### separated. One line for each will be drawn, with the exception of ### the min and max, which are already drawn. ## graph.hh.wealth <- function(inpath, infile, outpath, outpref, log.plot=FALSE, err.bar=TRUE, n.quantiles=0) { ##* ## Set the path and name of the input file ## - The 'paste' command concatenates the two ## - The 'skiplines' var sets the number of lines ## to skip when reading in the dataset. ##* if (substr(inpath, nchar(inpath), nchar(inpath)) == "/") inpath <- substr(inpath, 0, nchar(inpath)-1) if (substr(outpath, nchar(outpath), nchar(outpath)) == "/") outpath <- substr(outpath, 0, nchar(outpath)-1) pathfile <- paste(inpath, infile, sep="/") skiplines <- 1 ##* ## Set the names of the output file graphics ##* fnout.wlth <- "hhwealth.png" fnout.wlthss <- "hhwealth-sumstats.png" output.png.wlth <- paste(outpath, "/", outpref, fnout.wlth, sep="") output.png.wlthss <- paste(outpath, "/", outpref, fnout.wlthss, sep="") ##* ## Read in the household-level output dataset ##* hhstats <- read.delim(file=pathfile, header=TRUE, sep ="\t", dec=".", skip=skiplines) ##* ## Get some information from the household-level ## dataset for use in plotting. ## - the village number ## - a vector of the unique HH IDs ## - the maximum number of model run years ## - the maximum wealth among all households ##* villnum <- m
Re: [R] error "variable names are limited to 256 bytes" when sourcing code
On Wed, May 26, 2010 at 6:00 PM, Wu Gong wrote: > > I can only repeat your error message :) > > >> n256 <- paste(rep("A",256),collapse="") >> assign(n256, 1) >> n257 <- paste(rep("A",257),collapse="") >> assign(n257, 1) > Error in assign(n257, 1) : variable names are limited to 256 bytes > If a variable name can have 26 upper case + 26 lower case + 10 numbers then the number of possible variable names is: 711659926691456588820198688981513283237719214167524272940980007340737850\ 071505550367426050190853744948955339987662427844810850852717191846883823768674\ 280839119270574786535774460628640384757837267418932039347078114901615267344319\ 690975277428929737916031623809028545597238524149983532303848529517503894555603\ 08581357292749533632407679473157679404062823255544802787912646756996122962\ 654809395519130134923611540639384237080197541181260772381917961683956924416 which should be enough for everyone (that's probably a lower bound since names can have dots and underscores etc in them). I suspect the code is doing something very horrible with variable names, and needs to be restructured to use lists or vectors or arrays or anything other than encoding information into the name of an object. I had to calculate 62^256 in Maxima since R thinks it's infinite. Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error "variable names are limited to 256 bytes" when sourcing code
I can only repeat your error message :) > n256 <- paste(rep("A",256),collapse="") > assign(n256, 1) > n257 <- paste(rep("A",257),collapse="") > assign(n257, 1) Error in assign(n257, 1) : variable names are limited to 256 bytes - A R learner. -- View this message in context: http://r.789695.n4.nabble.com/error-variable-names-are-limited-to-256-bytes-when-sourcing-code-tp2231800p2232014.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] error "variable names are limited to 256 bytes" when sourcing code
I've written a function that takes some input data output from a simulation model and creates some graphs. It's not very complicated code, and it works perfectly fine if I just run the code as is. But I have converted it into a function so we call it externally, and when I try to source the code to test the function, I get the error message "variable names are limited to 256 bytes". I've tried searching online for a solution to this, but everything I have come across deals with this error in relation to input data, not a function. The code is 389 lines long, so I'd rather not paste it here and clog up inboxes. If you have an idea as to why this is happening and would like to see the code, please email me and I will send it to you. Thanks in advance. -- Brian Frizzelle Spatial Analysis Services Carolina Population Center University of North Carolina at Chapel Hill Voice: 919-966-6663 Fax: 919-966-6638 Email: brian_frizze...@unc.edu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.